package avicit.cbb.techclass.tabledefine.commtablemanager.action;

import avicit.cbb.tabledefine.service.api.CommTableManagerIntfsServiceApi;
import avicit.cbb.techclass.tabledefine.commtablemanager.domain.*;
import avicit.cbb.techclass.tabledefine.commtablemanager.action.service.CommTableManagerService;
import avicit.cbb.techclass.tabledefine.commtablemanager.action.service.api.CommTableManagerServiceApi;
import avicit.cbb.techclass.tabledefine.commtempletmanager.domain.CbbTempletCode;
import avicit.platform6.api.session.SessionHelper;
import avicit.platform6.api.sysshirolog.impl.AfterLoginSessionProcess;
import avicit.platform6.api.sysuser.SysOrgAPI;
import avicit.platform6.api.sysuser.dto.SysOrg;
import avicit.platform6.commons.utils.ComUtil;
import avicit.platform6.commons.utils.JsonHelper;
import avicit.platform6.commons.utils.RequestUtil;
import avicit.platform6.commons.utils.web.TreeNode;
import avicit.platform6.core.context.ThreadContextHelper;
import avicit.platform6.core.dao.Paging;
import avicit.platform6.core.properties.PlatformConstant.OpResult;
import avicit.platform6.core.jdbc.Page;

import net.sf.json.JSONObject;
import net.sf.json.JSONArray;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.util.*;

/**
 * 参考模版Controller 创建时间 ：2014-08-19
 *
 * @author 朱锋
 */
@SuppressWarnings({"unchecked","deprecation"})
@Controller
@RequestMapping("/aos/commtablemanagerController")
public class CommTableManagerController {

	@Autowired
	private CommTableManagerServiceApi commTableManagerService;
	@Autowired
	CommTableManagerIntfsServiceApi commTableManagerIntfsService;
	@Autowired
	CommSysInfoIntfsService commSysInfoIntfsService;
	@Autowired
	private SysOrgAPI sysOrgAPI;

	/**
	 * 字段基本信息新增，更新方法
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/saveCbbTabColumnsData")
	@ResponseBody
	public Map<String,Object> saveCbbTabColumnsData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String insertData = request.getParameter("insertData");
		String updateData = request.getParameter("updateData");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String nodeId = request.getParameter("nodeId");
		String nodeName = request.getParameter("nodeName");
		String tableName = request.getParameter("tableName");
		String isTrueTable = request.getParameter("isTrueTable");
		String nodeCode = request.getParameter("nodeCode");
		Map<String, Object> params = new HashMap<String, Object>();
		String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
		SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
		String orgCode = so.getOrgCode();
		params.put("orgCode", orgCode);
		params.put("orgId", ThreadContextHelper.getOrgId());
		params.put("deptId", ThreadContextHelper.getDeptId());
		// 张余修改
		// 获取当前页面多语言类型
		Object lang = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
		String languageCode = "zh_CN";
		if (lang != null) {
			languageCode = lang.toString();
		}
		params.put("languageCode", languageCode);
		try {
			// 更新
			if (!"".equals(updateData) && !"[]".equals(updateData)) {
				boolean isTrue = false;
				if ("Y".equals(isTrueTable)) { // 实体表
					isTrue = true;
				}
				CbbTabColumns[] ccArray = JsonUtils.newInstance().Json2BeanArray(updateData, CbbTabColumns.class);// 实体类列对象数组
				commTableManagerService.updateCbbTabColumns(ccArray, sysId, nodeId, nodeName, tableName, isTrue, params);// 更新基本字段及实体表信息
			}
			// 新增
			if (!"".equals(insertData) && !"[]".equals(insertData)) {
				CbbTabColumns[] ccArray = JsonUtils.newInstance().Json2BeanArray(insertData, CbbTabColumns.class);// 实体类列对象数组
				// 查询tableId
				String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
				if (!"".equals(tableId)) {
					// 存在，那么新增列信息及更新实体表
					commTableManagerService.insertCbbTabColumns(ccArray, sysId, nodeId, nodeName, tableName, ThreadContextHelper.getOrgId(), ThreadContextHelper.getDeptId(), SessionHelper.getLoginSysUserId(request), RequestUtil.getClientIp(request), isTrueTable);
					map.put("flag", OpResult.success);
				} else {
					boolean isTrue = false;
					if ("Y".equals(isTrueTable)) { // 实体表
						isTrue = true;
					}
					// 不存在，说明此系统标识及节点ID未创建过表，那么新增表信息，列信息，配置NODE信息,创建实体表及表单信息
					Map<String, Object> param = new HashMap<String, Object>();
					commTableManagerIntfsService.createCbbTableByIntfs(ThreadContextHelper.getOrgId(), ThreadContextHelper.getDeptId(), sysId, nodeId, nodeName, "1", "", SessionHelper.getLoginSysUserId(request), RequestUtil.getClientIp(request), isTrue, nodeCode, param);
					// 查询tableId
					tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
					map.put("flag", OpResult.success);
				}
			}
			map.put("flag", OpResult.success);
		} catch (Exception e) {
			map.put("flag", OpResult.failure);
			String msg = e.getCause().getMessage();
			int idx = msg.lastIndexOf(":");
			map.put("mes", msg.substring(idx + 1, msg.length()));
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 字段基本信息删除方法
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/deleteCbbTabColumnsData")
	@ResponseBody
	public Map<String,Object> deleteCbbTabColumnsData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String deleteData = request.getParameter("deleteData");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String nodeId = request.getParameter("nodeId");
		String nodeName = request.getParameter("nodeName");
		String tableName = request.getParameter("tableName");
		String isTrueTable = request.getParameter("isTrueTable");
		String orgId = ThreadContextHelper.getOrgId();
		String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
		SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
		String orgCode = so.getOrgCode();
		try {
			// 删除
			CbbTabColumns[] ccArray = JsonUtils.newInstance().Json2BeanArray(deleteData, CbbTabColumns.class);// 实体类列对象数组
			// 删除字段
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("orgCode", orgCode);
			commTableManagerService.deleteCommCbbTabColumnsById(ccArray, sysId, nodeId, nodeName, tableName, isTrueTable, orgId, param);
			if (ccArray.length != 0) {
				commTableManagerService.updateColOrder(ccArray[0].getTableId());
			}
			map.put("flag", OpResult.success);
		} catch (Exception e) {
			map.put("flag", OpResult.failure);
			map.put("mes", e.getMessage());
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 代码维护保存方法
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/saveCbbTabColumnsCodeData")
	@ResponseBody
	public ModelAndView saveCbbTabColumnsCodeData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView("");
		String insertData = request.getParameter("insertData");
		String updateData = request.getParameter("updateData");
		String updateCodeData = request.getParameter("updateCodeData");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String nodeId = request.getParameter("nodeId");
		String nodeName = request.getParameter("nodeName");
		String tableName = request.getParameter("tableName");
		// 查询tableId
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orgId", ThreadContextHelper.getOrgId());
		String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
		try {
			// 张余修改
			// 获取当前多语言类型
			Object lang = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
			String languageCode = "zh_CN";
			if (lang != null) {
				languageCode = lang.toString();
			}
			params.put("languageCode", languageCode);
			// 新增
			if (!"".equals(insertData) && !"[]".equals(insertData)) {
				commTableManagerService.insertTabColCodeByJson(insertData, tableId, sysId);// 调用新增方法
			}
			// 更新
			if ((!"".equals(updateData) && !"[]".equals(updateData)) || (!"".equals(updateCodeData) && !"[]".equals(updateCodeData))) {
				CbbTabColumns[] ccArray = JsonUtils.newInstance().Json2BeanArray(updateData, CbbTabColumns.class);// 实体类列对象数组
				if (ccArray.length > 0) {
					commTableManagerService.updateCbbTabColumnsTemp(ccArray, sysId, nodeId, nodeName);// 更新基本字段及实体表信息
				}
				// 实体类代码维护数组
				JSONArray ja = JSONArray.fromObject(updateCodeData);
				List<CbbTabColCode> ccArrayCode = new ArrayList<CbbTabColCode>();
				for (int i = 0; i < ja.size(); i++) {
					JSONObject jj = JSONObject.fromObject(ja.get(i));
					int codeOrder = Integer.parseInt(jj.getString("CODE_ORDER"));
					BigDecimal bOrder = new BigDecimal(codeOrder);
					String columnId = jj.getString("COLUMN_ID");
					String lookupName = jj.getString("LOOKUP_NAME");
					String lookupCode = jj.getString("LOOKUP_CODE");
					String codeIsValid = jj.getString("CODE_IS_VALID");
					String ctype = jj.getString("CTYPE");
					String id = jj.getString("ID");
					CbbTabColCode cbbTabColCode = new CbbTabColCode();
					cbbTabColCode.setId(id);
					cbbTabColCode.setTableId(tableId);
					cbbTabColCode.setColumnId(columnId);
					cbbTabColCode.setCodeOrder(bOrder);
					cbbTabColCode.setLookupName(lookupName);
					cbbTabColCode.setLookupCode(lookupCode);
					cbbTabColCode.setCodeIsValid(codeIsValid);
					if (id.equals("") || ctype.equals("S")) {
						continue;
					} else {
						ccArrayCode.add(cbbTabColCode);
					}
				}
				commTableManagerService.updateCbbTabColCode(ccArrayCode, sysId, nodeId, nodeName);// 更新代码维护信息
			}
			mav.addObject("flag", OpResult.success);
		} catch (Exception e) {
			mav.addObject("flag", OpResult.failure);
			e.printStackTrace();
		}
		mav.setView(null);
		return mav;
	}

	/**
	 * 代码维护保存方法
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/deleteCbbTabColumnsCodeData")
	@ResponseBody
	public Map<String,Object> deleteCbbTabColumnsCodeData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String deleteData = request.getParameter("deleteData");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		try {
			// 删除
			if (!"".equals(deleteData) && !"[]".equals(deleteData)) {
				JSONArray ja = JSONArray.fromObject(deleteData);
				for (int i = 0; i < ja.size(); i++) {
					JSONObject jj = JSONObject.fromObject(ja.get(i));
					String id = jj.getString("ID");
					if (!"".equals(id) && !"null".equals(id) && null != id) {
						String ctype = jj.getString("CTYPE");
						// 判断是否为系统通用代码
						if (ctype.equals("S")) {
							commTableManagerService.deleteCbbSysCodeRecord(id);
						} else {
							CbbTabColCode cbbTabColCode = commTableManagerService.getCbbTabColCodeById(id);
							commTableManagerService.deleteCbbTabColCodeById(cbbTabColCode);
						}
					}
				}
			}
			map.put("flag", OpResult.success);
		} catch (Exception e) {
			map.put("flag", OpResult.failure);
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 排序字段保存方法
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/saveCbbTabColSortData")
	@ResponseBody
	public Map<String,Object> saveCbbTabColSortData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String insertData = request.getParameter("insertData");
		String updateData = request.getParameter("updateData");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		try {
			// 新增
			if (!"".equals(insertData) && !"[]".equals(insertData)) {
				JSONArray ja = JSONArray.fromObject(insertData);
				for (int i = 0; i < ja.size(); i++) {
					JSONObject jj = JSONObject.fromObject(ja.get(i));
					String tableId = jj.getString("TABLE_ID");
					String columnId = jj.getString("COLUMN_ID");
					int sortOrder = Integer.parseInt(jj.getString("SORT_ORDER"));
					BigDecimal bOrder = new BigDecimal(sortOrder);
					String sortCode = jj.getString("SORT_CODE");
					CbbTabColSort cbbTabColSort = new CbbTabColSort();
					cbbTabColSort.setTableId(tableId);
					cbbTabColSort.setColumnId(columnId);
					cbbTabColSort.setSortOrder(bOrder);
					cbbTabColSort.setSortCode(sortCode);
					cbbTabColSort.setSysId(sysId);
					cbbTabColSort.setOrgId(ThreadContextHelper.getOrgId());
					cbbTabColSort.setDeptId(ThreadContextHelper.getDeptId());
					commTableManagerService.insertCbbTabColSorte(cbbTabColSort);// 调用新增方法
				}
			}
			// 更新
			if ((!"".equals(updateData) && !"[]".equals(updateData))) {
				JSONArray ja = JSONArray.fromObject(updateData);
				for (int i = 0; i < ja.size(); i++) {
					JSONObject jj = JSONObject.fromObject(ja.get(i));
					String id = jj.getString("ID");
					int sortOrder = Integer.parseInt(jj.getString("SORT_ORDER"));
					BigDecimal bOrder = new BigDecimal(sortOrder);
					String sortCode = jj.getString("SORT_CODE");
					CbbTabColSort cbbTabColSort = new CbbTabColSort();
					cbbTabColSort.setId(id);
					cbbTabColSort.setSortOrder(bOrder);
					cbbTabColSort.setSortCode(sortCode);
					commTableManagerService.updateCbbTabColSort(cbbTabColSort);// 调用更新方法
				}
			}
			map.put("flag", OpResult.success);
		} catch (Exception e) {
			map.put("flag", OpResult.failure);
			map.put("mes", "保存操作执行失败，请联系管理员！");
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 分类检索保存方法
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/saveCbbTabColSearchData")
	@ResponseBody
	public Map<String,Object> saveCbbTabColSearchData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String insertData = request.getParameter("insertData");
		String updateData = request.getParameter("updateData");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		try {
			// 新增
			if (!"".equals(insertData) && !"[]".equals(insertData)) {
				JSONArray ja = JSONArray.fromObject(insertData);
				for (int i = 0; i < ja.size(); i++) {
					JSONObject jj = JSONObject.fromObject(ja.get(i));
					String tableId = jj.getString("TABLE_ID");
					String columnId = jj.getString("COLUMN_ID");
					int searchOrder = Integer.parseInt(jj.getString("SEARCH_ORDER"));
					BigDecimal bOrder = new BigDecimal(searchOrder);
					CbbTabColSearch cbbTabColSearch = new CbbTabColSearch();
					cbbTabColSearch.setTableId(tableId);
					cbbTabColSearch.setColumnId(columnId);
					cbbTabColSearch.setSearchOrder(bOrder);
					cbbTabColSearch.setSysId(sysId);
					cbbTabColSearch.setOrgId(SessionHelper.getCurrentOrgId(request));
					cbbTabColSearch.setDeptId(SessionHelper.getCurrentDeptId(request));
					commTableManagerService.insertCbbTabColSearch(cbbTabColSearch);// 调用新增方法
				}
			}
			// 更新
			if ((!"".equals(updateData) && !"[]".equals(updateData))) {
				JSONArray ja = JSONArray.fromObject(updateData);
				for (int i = 0; i < ja.size(); i++) {
					JSONObject jj = JSONObject.fromObject(ja.get(i));
					String id = jj.getString("ID");
					int searchOrder = Integer.parseInt(jj.getString("SEARCH_ORDER"));
					BigDecimal bOrder = new BigDecimal(searchOrder);
					CbbTabColSearch cbbTabColSearch = commTableManagerService.getCbbTabColSearchById(id);
					cbbTabColSearch.setSearchOrder(bOrder);
					commTableManagerService.updateCbbTabColSearch(cbbTabColSearch);// 调用更新方法
				}
			}
			map.put("flag", OpResult.success);
		} catch (Exception e) {
			map.put("flag", OpResult.failure);
			map.put("mes", "保存操作执行失败，请联系管理员！");
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 删除排序字段
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/deleteCbbTabSortData")
	@ResponseBody
	public Map<String,Object> deleteCbbTabSortData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String deleteData = request.getParameter("deleteData");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		try {
			// 删除
			if (!"".equals(deleteData) && !"[]".equals(deleteData)) {
				JSONArray ja = JSONArray.fromObject(deleteData);
				for (int i = 0; i < ja.size(); i++) {
					JSONObject jj = JSONObject.fromObject(ja.get(i));
					String id = jj.getString("ID");
					if (!"".equals(id)) {
						commTableManagerService.deleteCbbTabSort(id);
					}
				}
			}
			map.put("flag", OpResult.success);
		} catch (Exception e) {
			map.put("flag", OpResult.failure);
			map.put("mes", "执行删除操作异常，请联系管理员！");
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 删除分类检索字段
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/deleteCbbTabSearchData")
	@ResponseBody
	public Map<String,Object> deleteCbbTabSearchData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String deleteData = request.getParameter("deleteData");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		try {
			// 删除
			if (!"".equals(deleteData) && !"[]".equals(deleteData)) {
				JSONArray ja = JSONArray.fromObject(deleteData);
				for (int i = 0; i < ja.size(); i++) {
					JSONObject jj = JSONObject.fromObject(ja.get(i));
					String id = jj.getString("ID");
					if (!"".equals(id)) {
						commTableManagerService.deleteCbbTabSearch(id);
					}
				}
			}
			map.put("flag", OpResult.success);
		} catch (Exception e) {
			map.put("flag", OpResult.failure);
			map.put("mes", "执行删除操作异常，请联系管理员！");
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 节点著录定义更新方法
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/updateCbbTabRecordData")
	public ModelAndView updateCbbTabRecorData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView("");
		String updateData = request.getParameter("updateData");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String nodeId = request.getParameter("nodeId");
		String tableId = request.getParameter("tableId");
		String fileFlag = request.getParameter("fileFlag"); // 文件标识，BUMJ：部门文件；GRWJ：个人文件
		try {
			if (!"".equals(updateData) && !"[]".equals(updateData)) {
				List<CbbTabColumns> list = new ArrayList<CbbTabColumns>();
				JSONArray ja = JSONArray.fromObject(updateData);
				for (int i = 0; i < ja.size(); i++) {
					JSONObject jj = JSONObject.fromObject(ja.get(i));
					String id = jj.getString("ID");
					String colIsVisible = jj.getString("COL_IS_VISIBLE");
					String colIsTabVisible = jj.getString("COL_IS_TAB_VISIBLE");
					String colIsDetail = jj.getString("COL_IS_DETAIL");
					String colIsSearch = jj.getString("COL_IS_SEARCH");
					int colOrder = Integer.parseInt(jj.getString("COL_ORDER"));
					CbbTabColumns cbbTabColumns = new CbbTabColumns();
					cbbTabColumns.setId(id);
					cbbTabColumns.setColIsVisible(colIsVisible);
					cbbTabColumns.setColIsTabVisible(colIsTabVisible);
					cbbTabColumns.setColIsDetail(colIsDetail);
					cbbTabColumns.setColIsSearch(colIsSearch);
					BigDecimal num = new BigDecimal(colOrder);
					cbbTabColumns.setColOrder(num);
					list.add(cbbTabColumns);
				}
				// 获取TABNODEID
				String tabNodeId = "";
				if ("GRWJ".equals(fileFlag) || "BMWJ".equals(fileFlag)) {
					// 如果是文件下的物理表，则将父节点的ID作为tabNodeId
					tabNodeId = nodeId;
				} else {
					tabNodeId = commTableManagerService.getCbbTabNodeId(sysId, nodeId, tableId);
				}
				commTableManagerService.updateCbbTabRecord(list, sysId, tabNodeId, SessionHelper.getCurrentOrgId(request), SessionHelper.getCurrentDeptId(request), tableId);// 更新节点著录信息
			}
			mav.addObject("flag", OpResult.success);
		} catch (Exception e) {
			mav.addObject("flag", OpResult.failure);
			e.printStackTrace();
		}
		mav.setView(null);
		return mav;
	}

	/**
	 * 节点著录定义还原方法
	 *
	 * @author zhangzm
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/restoreCbbTabRecordData")
	public ModelAndView restoreCbbTabRecordData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView("");
//		String updateData = request.getParameter("updateData");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String nodeId = request.getParameter("nodeId");
		String tableId = request.getParameter("tableId");
		String fileFlag = request.getParameter("fileFlag"); // 文件标识，BUMJ：部门文件；GRWJ：个人文件
		try {

			// 获取TABNODEID
			String tabNodeId = "";
			if ("GRWJ".equals(fileFlag) || "BMWJ".equals(fileFlag)) {
				// 如果是文件下的物理表，则将父节点的ID作为tabNodeId
				tabNodeId = nodeId;
			} else {
				tabNodeId = commTableManagerService.getCbbTabNodeId(sysId, nodeId, tableId);
			}
			commTableManagerService.restoreCbbTabRecordData(tabNodeId, tableId);// 还原节点著录信息

			mav.addObject("flag", OpResult.success);
		} catch (Exception e) {
			mav.addObject("flag", OpResult.failure);
			e.printStackTrace();
		}
		mav.setView(null);
		return mav;
	}

	/**
	 * 获取基本字段信息
	 *
	 * @author 朱锋
	 * @param response
	 * @param request
	 * @return ModelAndView
	 * @throws Exception
	 *             ModelAndView
	 */
	@RequestMapping(value = "/getCbbTabColumnsData")
	@ResponseBody
	public Map<String,Object> getCbbTabColumnsData(HttpServletResponse response, HttpServletRequest request) throws Exception {
		Map<String,Object> maps = new HashMap<>();
		String json = request.getParameter("param");
		String sysId = request.getParameter("sysId");
		String isTemplet = request.getParameter("isTemplet");
		sysId = "LANTOP";
		String tableName = request.getParameter("tableName");
		// 查询tableId
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orgId", ThreadContextHelper.getOrgId());
		String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
		if (tableId.equals("")) {
			tableId = "@@@";
		}
		Map<String, Object> parameter = new HashMap<String, Object>();
		if (json != null && !"".equals(json)) {
			parameter = JsonHelper.getInstance().readValue(json, Map.class);
		}
		// SanXiaFiles Create By Tangkun Start
		String inputWord1 = request.getParameter("inputWord");
		if (inputWord1 != null && !"".equals(inputWord1)) {
			String inputWord = URLDecoder.decode(inputWord1, "utf-8");
			parameter.put("inputWord", inputWord);
		}
		// SanXiaFiles Create By Tangkun End
		parameter.put("tableId", tableId);
		parameter.put("isTemplet", isTemplet);
		String pageNo = request.getParameter("page");// 取得当前页码
		String pageSize = request.getParameter("rows");// 取得一页显示的数量

		Paging<CbbTabColumns> page = new Paging<CbbTabColumns>();
		page.setPageSize(ComUtil.getPageSize(pageSize));
		page.setPageNo(ComUtil.getPageNo(pageNo));

		Map<String, Object> map = commTableManagerService.getPageDetailList(page, parameter, sysId);
		int count = Integer.valueOf(String.valueOf(map.get("count")));
		// 由于修改时JSON串传出的以下两个属性为毫秒数,无法映射到对象里,所以此时把这两个置为空
		List<CbbTabColumns> list = (List<CbbTabColumns>) map.get("list");
		for (CbbTabColumns cbbTabColumns : list) {
			cbbTabColumns.setCreationDate(null);
			cbbTabColumns.setLastUpdateDate(null);
		}
		maps.put("total", count);
		maps.put("rows", list);
		return maps;
	}

	/**
	 * 隐藏表格获取基本字段信息
	 *
	 * @author 郭亮
	 * @param response
	 * @param request
	 * @return ModelAndView
	 * @throws Exception
	 *             ModelAndView
	 */
	@RequestMapping(value = "/getHiddenCbbTabColumnsData")
	public Map<String,Object> getHiddenCbbTabColumnsData(HttpServletResponse response, HttpServletRequest request) throws Exception {
		Map<String,Object> maps = new HashMap<>();
		String json = request.getParameter("param");
		String sysId = request.getParameter("sysId");
		String isTemplet = request.getParameter("isTemplet");
		sysId = "LANTOP";
		String tableName = request.getParameter("tableName");
		// 查询tableId
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orgId", ThreadContextHelper.getOrgId());
		String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
		if (tableId.equals("")) {
			tableId = "@@@";
		}
		Map<String, Object> parameter = new HashMap<String, Object>();
		if (json != null && !"".equals(json)) {
			parameter = JsonHelper.getInstance().readValue(json, Map.class);
		}
		parameter.put("tableId", tableId);
		parameter.put("isTemplet", isTemplet);
		String pageNo = request.getParameter("page");// 取得当前页码
		String pageSize = request.getParameter("rows");// 取得一页显示的数量
		Paging<CbbTabColumns> page = new Paging<CbbTabColumns>();
		page.setPageSize(ComUtil.getPageSize(pageSize));
		page.setPageNo(ComUtil.getPageNo(pageNo));
		Map<String, Object> map = commTableManagerService.getHiddenPageDetailList(page, parameter, sysId);
		int count = Integer.valueOf(String.valueOf(map.get("count")));
		// 由于修改时JSON串传出的以下两个属性为毫秒数,无法映射到对象里,所以此时把这两个置为空
		List<CbbTabColumns> list = (List<CbbTabColumns>) map.get("list");
		for (CbbTabColumns cbbTabColumns : list) {
			cbbTabColumns.setCreationDate(null);
			cbbTabColumns.setLastUpdateDate(null);
		}
		maps.put("total", count);
		maps.put("rows", list);
		return maps;
	}

	/**
	 * 获取基本字段信息(只用于著录定义页面初始化，添加了页面初始化值转换为显示值)
	 *
	 * @author 朱锋
	 * @param response
	 * @param request
	 * @return ModelAndView
	 * @throws Exception
	 *             ModelAndView
	 */
	@RequestMapping(value = "/getCbbTabColumnsDataForZL")
	@ResponseBody
	public Map<String,Object> getCbbTabColumnsDataForZL(HttpServletResponse response, HttpServletRequest request) throws Exception {
		Map<String,Object> maps = new HashMap<>();
		String json = request.getParameter("param");
		String sysId = request.getParameter("sysId");
		String isTemplet = request.getParameter("isTemplet");
		sysId = "LANTOP";
		String tableName = request.getParameter("tableName");
		// 查询tableId
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orgId", ThreadContextHelper.getOrgId());
		String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
		if (tableId.equals("")) {
			tableId = "@@@";
		}
		Map<String, Object> parameter = new HashMap<String, Object>();
		if (json != null && !"".equals(json)) {
			parameter = JsonHelper.getInstance().readValue(json, Map.class);
		}
		parameter.put("tableId", tableId);
		parameter.put("isTemplet", isTemplet);
		String pageNo = request.getParameter("page");// 取得当前页码
		String pageSize = request.getParameter("rows");// 取得一页显示的数量

		Paging<CbbTabColumns> page = new Paging<CbbTabColumns>();
		page.setPageSize(ComUtil.getPageSize(pageSize));
		page.setPageNo(ComUtil.getPageNo(pageNo));

		Map<String, Object> map = commTableManagerService.getPageDetailListForZL(page, parameter, sysId);
		int count = Integer.valueOf(String.valueOf(map.get("count")));
		// 由于修改时JSON串传出的以下两个属性为毫秒数,无法映射到对象里,所以此时把这两个置为空
		List<CbbTabColumns> list = (List<CbbTabColumns>) map.get("list");
		for (CbbTabColumns cbbTabColumns : list) {
			cbbTabColumns.setCreationDate(null);
			cbbTabColumns.setLastUpdateDate(null);
		}
		maps.put("total", count);
		maps.put("rows", list);
		return maps;
	}

	/**
	 * 获取索引主界面表格数据
	 *
	 * @author 朱锋
	 * @param response
	 * @param request
	 * @return ModelAndView
	 * @throws Exception
	 *             ModelAndView
	 */
	@RequestMapping(value = "/getCbbTabIndexData")
	@ResponseBody
	public Map<String,Object> getCbbTabIndexData(HttpServletResponse response, HttpServletRequest request) throws Exception {
		Map<String,Object> maps = new HashMap<>();
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String tableName = request.getParameter("tableName");
		// 查询tableId
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orgId", ThreadContextHelper.getOrgId());
		String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
		if (tableId.equals("")) {
			tableId = "@@@";
		}
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("tableId", tableId);
		String pageNo = request.getParameter("page");// 取得当前页码
		String pageSize = request.getParameter("rows");// 取得一页显示的数量

		Paging<CbbTabColumns> page = new Paging<CbbTabColumns>();
		page.setPageSize(ComUtil.getPageSize(pageSize));
		page.setPageNo(ComUtil.getPageNo(pageNo));
		Map<String, Object> map = commTableManagerService.getIndexPageDetailList(page, parameter, sysId);
		int count = Integer.valueOf(String.valueOf(map.get("count")));
		List<Map<String, Object>> list = (List<Map<String, Object>>) map.get("list");
		maps.put("total", count);
		maps.put("rows", list);
		return maps;
	}

	/**
	 * 获取排序主表信息
	 *
	 * @author 朱锋
	 * @param response
	 * @param request
	 * @return ModelAndView
	 * @throws Exception
	 *             ModelAndView
	 */
	@RequestMapping(value = "/getCbbTabSortData")
	@ResponseBody
	public Map<String,Object> getCbbTabSortData(HttpServletResponse response, HttpServletRequest request) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String sysId = request.getParameter("sysId");
		String isTemplet = request.getParameter("isTemplet");
		sysId = "LANTOP";
		String tableName = request.getParameter("tableName");
		// 查询tableId
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orgId", ThreadContextHelper.getOrgId());
		String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
		if (tableId.equals("")) {
			tableId = "@@@";
		}
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("tableId", tableId);
		parameter.put("isTemplet", isTemplet);
		String pageNo = request.getParameter("page");// 取得当前页码
		String pageSize = request.getParameter("rows");// 取得一页显示的数量
		// SanXiaFiles Create By Tangkun Start
		String inputWord1 = request.getParameter("inputWord");
		if (inputWord1 != null && !"".equals(inputWord1)) {
			String inputWord = URLDecoder.decode(inputWord1, "utf-8");
			parameter.put("inputWord", inputWord);
		}
		// SanXiaFiles Create By Tangkun End
		Paging<CbbTabColumns> page = new Paging<CbbTabColumns>();
		page.setPageSize(ComUtil.getPageSize(pageSize));
		page.setPageNo(ComUtil.getPageNo(pageNo));
		Page<Map<String, Object>> result = commTableManagerService.getPageTabSortList(page, parameter);
		map.put("total", result.getEntityCount()); // total键
		map.put("rows", result.getEntities()); // rows键 存放每页记录 list
		return map;
	}

	/**
	 * 获取排序子表信息
	 *
	 * @author 朱锋
	 * @param response
	 * @param request
	 * @return ModelAndView
	 * @throws Exception
	 *             ModelAndView
	 */
	@RequestMapping(value = "/getCbbTabColSortData")
	@ResponseBody
	public Map<String,Object> getCbbTabColSortData(HttpServletResponse response, HttpServletRequest request) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String tableName = request.getParameter("tableName");
		// 查询tableId
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orgId", ThreadContextHelper.getOrgId());
		String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
		if (tableId.equals("")) {
			tableId = "@@@";
		}
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("tableId", tableId);
		String pageNo = request.getParameter("page");// 取得当前页码
		String pageSize = request.getParameter("rows");// 取得一页显示的数量

		Paging<CbbTabColumns> page = new Paging<CbbTabColumns>();
		page.setPageSize(ComUtil.getPageSize(pageSize));
		page.setPageNo(ComUtil.getPageNo(pageNo));
		Page<Map<String, Object>> result = commTableManagerService.getCbbTabColSortData(page, parameter);
		map.put("total", result.getEntityCount()); // total键
		map.put("rows", result.getEntities()); // rows键 存放每页记录 list
		return map;
	}

	/**
	 * 获取分类检索主表信息
	 *
	 * @author 朱锋
	 * @param response
	 * @param request
	 * @return ModelAndView
	 * @throws Exception
	 *             ModelAndView
	 */
	@RequestMapping(value = "/getCbbTabSearchData")
	@ResponseBody
	public Map<String,Object> getCbbTabSearchData(HttpServletResponse response, HttpServletRequest request) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String sysId = request.getParameter("sysId");
		String isTemplet = request.getParameter("isTemplet");
		sysId = "LANTOP";
		String tableName = request.getParameter("tableName");
		// 查询tableId
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orgId", ThreadContextHelper.getOrgId());
		String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
		if (tableId.equals("")) {
			tableId = "@@@";
		}
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("tableId", tableId);
		parameter.put("isTemplet", isTemplet);
		String pageNo = request.getParameter("page");// 取得当前页码
		String pageSize = request.getParameter("rows");// 取得一页显示的数量
		// SanXiaFiles Create By Tangkun Start
		String inputWord1 = request.getParameter("inputWord");
		if (inputWord1 != null && !"".equals(inputWord1)) {
			String inputWord = URLDecoder.decode(inputWord1, "utf-8");
			parameter.put("inputWord", inputWord);
		}
		// SanXiaFiles Create By Tangkun End
		Paging<CbbTabColumns> page = new Paging<CbbTabColumns>();
		page.setPageSize(ComUtil.getPageSize(pageSize));
		page.setPageNo(ComUtil.getPageNo(pageNo));
		Page<Map<String, Object>> result = commTableManagerService.getPageTabSearchList(page, parameter);
		map.put("total", result.getEntityCount()); // total键
		map.put("rows", result.getEntities()); // rows键 存放每页记录 list
		return map;
	}

	/**
	 * 获取分类检索子表信息
	 *
	 * @author 朱锋
	 * @param response
	 * @param request
	 * @return ModelAndView
	 * @throws Exception
	 *             ModelAndView
	 */
	@RequestMapping(value = "/getCbbTabColSearchData")
	@ResponseBody
	public Map<String,Object> getCbbTabColSearchData(HttpServletResponse response, HttpServletRequest request) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String tableName = request.getParameter("tableName");
		// 查询tableId
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orgId", ThreadContextHelper.getOrgId());
		String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
		if (tableId.equals("")) {
			tableId = "@@@";
		}
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("tableId", tableId);
		String pageNo = request.getParameter("page");// 取得当前页码
		String pageSize = request.getParameter("rows");// 取得一页显示的数量

		Paging<CbbTabColumns> page = new Paging<CbbTabColumns>();
		page.setPageSize(ComUtil.getPageSize(pageSize));
		page.setPageNo(ComUtil.getPageNo(pageNo));
		Page<Map<String, Object>> result = commTableManagerService.getCbbTabColSearchData(page, parameter);
		map.put("total", result.getEntityCount()); // total键
		map.put("rows", result.getEntities()); // rows键 存放每页记录 list
		return map;
	}

	/**
	 * 获取节点著录定义列表信息
	 *
	 * @author 朱锋
	 * @param response
	 * @param request
	 * @return ModelAndView
	 * @throws Exception
	 *             ModelAndView
	 */
	@RequestMapping(value = "/getNodeRecordData")
	public ModelAndView getNodeRecordData(HttpServletResponse response, HttpServletRequest request) throws Exception {
		ModelAndView mav = new ModelAndView("");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String tableId = request.getParameter("tableId");
		String nodeId = request.getParameter("nodeId");
		String pageNo = request.getParameter("page");// 取得当前页码
		String pageSize = request.getParameter("rows");// 取得一页显示的数量
		String fileFlag = request.getParameter("fileFlag"); // 文件标识，BUMJ：部门文件；GRWJ：个人文件
		Map<String, Object> parameter = new HashMap<String, Object>();
		// 获取NODEID
		String tabNodeId = "";
		if ("BMWJ".equals(fileFlag) || "GRWJ".equals(fileFlag)) {
			// 如果是文件下的物理表，则将父节点的ID作为tabNodeId
			tabNodeId = nodeId;
		} else {
			tabNodeId = commTableManagerService.getCbbTabNodeId(sysId, nodeId, tableId);
		}
		// 判断是否已经在节点著录表生成数据
		boolean flag = commTableManagerService.checkNodeRecord(tabNodeId, tableId);
		if (!flag) {
			// 不存在，那么展示基本字段中的信息
			parameter.put("tableId", tableId);
			Paging<CbbTabColumns> page = new Paging<CbbTabColumns>();
			page.setPageSize(ComUtil.getPageSize(pageSize));
			page.setPageNo(ComUtil.getPageNo(pageNo));
			Page<Map<String, Object>> result = new Page<Map<String, Object>>();
			result = commTableManagerService.getPageNodeRecordColList(page, parameter);
			mav.addObject("total", result.getEntityCount()); // total键
			mav.addObject("rows", result.getEntities()); // rows键 存放每页记录 list
			return mav;

		} else {
			// 存在，那么展示节点著录定义中的信息
			parameter.put("tabNodeId", tabNodeId);
			parameter.put("tableId", tableId);
			Paging<CbbTabColumns> page = new Paging<CbbTabColumns>();
			page.setPageSize(ComUtil.getPageSize(pageSize));
			page.setPageNo(ComUtil.getPageNo(pageNo));
			Page<Map<String, Object>> result = new Page<Map<String, Object>>();
			result = commTableManagerService.getPageNodeRecordList(page, parameter);
			mav.addObject("total", result.getEntityCount()); // total键
			mav.addObject("rows", result.getEntities()); // rows键 存放每页记录 list
			return mav;
		}
	}

	/**
	 * 跳转参考模板页面
	 *
	 * @author 朱锋
	 * @param request
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/toCommTemplet")
	public ModelAndView toCommTemplet(HttpServletRequest request) throws Exception {
		ModelAndView mav = new ModelAndView();
		String dialogId = request.getParameter("dialogId");
		String sysId = request.getParameter("sysId");// 系统标识
		sysId = "LANTOP";
		String tableName = request.getParameter("tableName");// 节点名称
		String nodeId = request.getParameter("nodeId");// 节点名称
		String copyNodeData = request.getParameter("copyNodeData");// 复制页面的第二颗树 数据源 视图

		mav.addObject("dialogId", dialogId);
		mav.addObject("sysId", sysId);
		mav.addObject("nodeId", nodeId);
		mav.addObject("tableName", tableName);
		mav.addObject("copyNodeData", copyNodeData);
		mav.setViewName("avicit/cbb/techclass/tabledefine/commtablemanager/table_templet_manager");
		return mav;
	}

	/**
	 * 分类树加载
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/findChildsNode")
	public ModelAndView findChildsNode(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView();
		String parentId = request.getParameter("parentId");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		List<TreeNode> nodes = new ArrayList<TreeNode>();
		String id = parentId;
		try {
			// 默认为根节点
			if (StringUtils.isEmpty(id)) {
				id = "ROOT";
			}
			// 添加orgId过滤 update by gl 2016-04-14
			nodes = commTableManagerService.getTableTreeNodes(id, sysId, SessionHelper.getCurrentOrgId(request));
			mv.addObject("result", OpResult.success.ordinal());
		} catch (Exception e) {
			mv.addObject("result", OpResult.failure.ordinal());
			mv.addObject("msg", "后台处理异常，" + e.getMessage());
		}
		mv.addObject("data", nodes);
		return mv;
	}

	/**
	 * 复制参考模板字段信息操作
	 *
	 * @author 朱锋
	 * @param request
	 * @return ModelAndView
	 * @throws
	 */
	@RequestMapping("/copyCommTempletField")
	public ModelAndView copyCommTempletField(HttpServletRequest request) {
		ModelAndView mav = new ModelAndView();
		try {
			String ids = request.getParameter("ids");
			String sysId = request.getParameter("sysId");
			sysId = "LANTOP";
			String tableName = request.getParameter("tableName");
			String nodeId = request.getParameter("nodeId");
			String isStructure = request.getParameter("isStructure");// Y:库结构树对应字段;N:参考模板树对应字段
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("nodeId", nodeId);
			if (null != ids && !"".equals(ids)) {
				if ("Y".equals(isStructure)) {
					// 复制库结构树对应字段
					commTableManagerService.copyCbbTabColumns(ids, sysId, tableName, SessionHelper.getCurrentOrgId(request), SessionHelper.getCurrentDeptId(request), param);
				} else {
					// 复制参考模板树对应字段
					commTableManagerService.copyCommTempletField(ids, sysId, tableName, SessionHelper.getCurrentOrgId(request), SessionHelper.getCurrentDeptId(request));
				}
				Map<String, Object> params = new HashMap<String, Object>();
				params.put("orgId", SessionHelper.getCurrentOrgId(request));
				String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
				commTableManagerService.updateColOrder(tableId);
				mav.addObject("flag", OpResult.success);
			}
		} catch (Exception e) {
			e.printStackTrace();
			mav.addObject("flag", OpResult.failure);
		}
		mav.setView(null);
		return mav;
	}

	/**
	 * 获取列代码信息
	 *
	 * @author 朱锋
	 * @param response
	 * @param request
	 * @return ModelAndView
	 * @throws Exception
	 *             ModelAndView
	 */
	@RequestMapping(value = "/getCommTabColCodeData")
	public Map<String,Object> getCommTempletCodeData(HttpServletResponse response, HttpServletRequest request) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String cid = request.getParameter("cid");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String tableName = request.getParameter("tableName");
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("cid", cid);
		parameter.put("sysId", sysId);
		parameter.put("tableName", tableName);
		parameter.put("orgId", ThreadContextHelper.getOrgId());
		Paging<CbbTempletCode> page = new Paging<CbbTempletCode>();
		String pageNo = request.getParameter("page");// 取得当前页码
		String pageSize = request.getParameter("rows");// 取得一页显示的数量
		page.setPageSize(ComUtil.getPageSize(pageSize));
		page.setPageNo(ComUtil.getPageNo(pageNo));
		Page<Map<String, Object>> result = commTableManagerService.getPageCodeDetailList(page, parameter);
		map.put("total", result.getEntityCount()); // total键
		map.put("rows", result.getEntities()); // rows键 存放每页记录 list
		return map;
	}

	/**
	 * 系统通用代码选择页面
	 *
	 * @author 朱锋
	 * @param request
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/toCommTempletScodeAdd")
	public ModelAndView toCommTempletScodeAdd(HttpServletRequest request) throws Exception {
		ModelAndView mav = new ModelAndView();
		String dialogId = request.getParameter("dialogId");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String fId = request.getParameter("fid");
		String tableName = request.getParameter("tableName");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orgId", ThreadContextHelper.getOrgId());
		String tid = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
		mav.addObject("dialogId", dialogId);
		mav.addObject("sysId", sysId);
		mav.addObject("fId", fId);
		mav.addObject("tId", tid);
		mav.setViewName("avicit/cbb/techclass/tabledefine/commtablemanager/table_sys_code_manager");
		return mav;
	}

	/**
	 * 系统通用代码导入方法
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/insertSysCodeData")
	@ResponseBody
	public Map<String,Object> insertSysCodeData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String cid = request.getParameter("cid");
		String tid = request.getParameter("tid");
		String fid = request.getParameter("fid");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		try {
			commTableManagerService.insertSysCode(cid, tid, fid, sysId, ThreadContextHelper.getOrgId(), ThreadContextHelper.getDeptId());
			map.put("flag", OpResult.success);
		} catch (Exception e) {
			map.put("flag", OpResult.failure);
		}
		return map;
	}

	/**
	 * 字段基本信息更新方法
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/createMenu")
	public Map<String,Object> createMenu(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String nodeId = request.getParameter("nodeId");
		String nodeName = request.getParameter("nodeName");
		String tableName = request.getParameter("tableName");
		// 查询tableId
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orgId", ThreadContextHelper.getOrgId());
		String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
		try {
			if (!tableId.equals("")) {
				// 存在，那么判断是否已经创建菜单
				StringBuffer sb = new StringBuffer();
				sb.append("platform/cbb/billDefineManagerController/toFormApp");
				sb.append("?sysId=" + sysId + "&nodeId=" + nodeId + "&nodeName=" + nodeName + "&tableName=" + tableName);
				if (commTableManagerService.checkMenuPath(sb.toString())) {
					// 该菜单已经存在
					map.put("flag", OpResult.success);
					map.put("msg", "请勿重复创建菜单！");
				} else {
					commTableManagerService.createMenu(sb.toString(), sysId, tableName, params);
					map.put("flag", OpResult.success);
					map.put("msg", "成功创建菜单！");
				}
			} else {
				// 不存在，那么给用户提示，请先创建库表
				map.put("flag", OpResult.success);
				map.put("msg", "无法创建菜单，请先创建库表！");
			}
		} catch (Exception e) {
			map.put("flag", OpResult.failure);
			map.put("msg", "创建菜单出现异常，请联系管理员！");
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 字段基本信息更新方法(不操作数据库实体表)
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/updateCbbTabColumnsData")
	@ResponseBody
	public Map<String,Object> updateCbbTabColumnsData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String json = request.getParameter("param");// "colIsDetail": "Y",
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
		SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
		String orgCode = so.getOrgCode();
		String nodeId = request.getParameter("nodeId");
		String nodeName = request.getParameter("nodeName");
		String tableName = request.getParameter("tableName");
		String type = request.getParameter("type");// 操作页面标识（目前只判断【代码维护】页面）
		CbbTabColumns[] ccArray = JsonUtils.newInstance().Json2BeanArray(json, CbbTabColumns.class);// 实体类列对象数组
		// 如果是【代码维护】页面，那么给【生成方式】字段复制
		if ("code".equals(type)) {
			if (ccArray.length > 0) {
				for (int i = 0; i < ccArray.length; i++) {
					CbbTabColumns cbbTabColumns = ccArray[i];
					String colDropdownType = cbbTabColumns.getColDropdownType();// 类型
					String colGeneMethod = cbbTabColumns.getColGeneMethod();// 生成方式
					if ("1".equals(colGeneMethod) || "2".equals(colGeneMethod)) { // 默认值
						if ("0".equals(colDropdownType)) { // 无
							String colValue = cbbTabColumns.getColValueName();// 【生成方式显示值】
							cbbTabColumns.setColGeneMethodRule(colValue);
						}
					}
					// 根据字段ID查找字段旧的配置信息
					String columnId = cbbTabColumns.getId();
					CbbTabColumns cbbTabColumnsOld = commTableManagerService.getCbbTabColumnsById(columnId);
					String colGeneMethodOld = cbbTabColumnsOld.getColGeneMethod();
					if (!(colGeneMethodOld.equals(colGeneMethod))) { // 改变了生成方式的前提下进行删除
						// 如果为组合项或者统计生成则删除旧的配置信息
						if ("4".equals(colGeneMethodOld) || "5".equals(colGeneMethodOld)) {
							commTableManagerService.deleteConfig(columnId);
						}
					}
				}
			}
		}
		/*** add by gl 2016-01-28 start 设置生成方式 ***/
		String idSet = request.getParameter("idSet"); // 设置字段ID
		String colGeneMethod = request.getParameter("colGeneMethod");
		String colGeneMethodRule = request.getParameter("colGeneMethodRule");
		String groupJson = request.getParameter("groupJson");// 组合项配置信息

		//add by zhangjq 2019-8-3
		//显示组合项生成规则的中文
		String colGeneMethodRuleText = request.getParameter("colGeneMethodRuleText");
		String colGeneMethodRuleParam = colGeneMethodRule;
		//end add

		// 统计生成配置信息
		String operation = request.getParameter("operation");// 统计生成运算方式
		String groupSelect1 = request.getParameter("groupSelect1");
		String groupSelect2 = request.getParameter("groupSelect2");
		String groupSelect3 = request.getParameter("groupSelect3");
		String groupInput1 = request.getParameter("groupInput1");
		String groupInput2 = request.getParameter("groupInput2");
		if (null != idSet && !"".equals(idSet) && !"null".equals(idSet)) {
			if (ccArray.length > 0) {
				for (int i = 0; i < ccArray.length; i++) {
					String colId = ccArray[i].getId();
					if (idSet.equals(colId)) {
						// 如果为组合项，解析配置json，设置生成方式规则值
						if ("4".equals(colGeneMethod)) {
							String configGroupValue = "";
							JSONArray ja = JSONArray.fromObject(groupJson);
							for (int j = 0; j < ja.size(); j++) {
								JSONObject jj = JSONObject.fromObject(ja.get(j));
								String tgtColumnId = jj.getString("0");// 组合字段
								String tgtInput = jj.getString("1");// 组合固定值
								if (null != tgtColumnId && !"".equals(tgtColumnId) && !"null".equals(tgtColumnId)) {
									configGroupValue = configGroupValue + "+" + tgtColumnId;
								}
								if (null != tgtInput && !"".equals(tgtInput) && !"null".equals(tgtInput)) {
									configGroupValue = configGroupValue + "+\"" + tgtInput + "\"";
								}
							}
							if (!"".equals(configGroupValue)) {
								configGroupValue = configGroupValue.substring(1);
							}
							colGeneMethodRule = configGroupValue;
						}
						// 给对象设置配置信息
						ccArray[i].setColGeneMethod(colGeneMethod);
						//add by zhangjq 2019-8-3
						//ccArray[i].setColGeneMethodRule(colGeneMethodRule);
						ccArray[i].setColGeneMethodRule(colGeneMethodRuleParam);
						ccArray[i].setColGeneMethodRuleText(colGeneMethodRuleText);
						//end add
					}
				}
			} else {
				// 根据ID查询对象，设置新的生成方式
				CbbTabColumns cbbTabColumnsChange = commTableManagerService.getCbbTabColumnsById(idSet);
				// 如果为组合项，解析配置json，设置生成方式规则值
				if ("4".equals(colGeneMethod)) {
					String configGroupValue = "";
					JSONArray ja = JSONArray.fromObject(groupJson);
					for (int j = 0; j < ja.size(); j++) {
						JSONObject jj = JSONObject.fromObject(ja.get(j));
						String tgtColumnId = jj.getString("0");// 组合字段
						String tgtInput = jj.getString("1");// 组合固定值
						if (null != tgtColumnId && !"".equals(tgtColumnId) && !"null".equals(tgtColumnId)) {
							configGroupValue = configGroupValue + "+" + tgtColumnId;
						}
						if (null != tgtInput && !"".equals(tgtInput) && !"null".equals(tgtInput)) {
							configGroupValue = configGroupValue + "+\"" + tgtInput + "\"";
						}
					}
					if (!"".equals(configGroupValue)) {
						configGroupValue = configGroupValue.substring(1);
					}
					colGeneMethodRule = configGroupValue;
				}
				// 给对象设置配置信息
				cbbTabColumnsChange.setColGeneMethod(colGeneMethod);
				//add by zhangjq 2019-8-3
				//cbbTabColumnsChange.setColGeneMethodRule(colGeneMethodRule);
				cbbTabColumnsChange.setColGeneMethodRule(colGeneMethodRuleParam);
				cbbTabColumnsChange.setColGeneMethodRuleText(colGeneMethodRuleText);
				//end add
				// 将对象放入集合中用于更新
				ccArray = new CbbTabColumns[1];
				ccArray[0] = cbbTabColumnsChange;
			}
		}
		/*** add by gl 2016-01-28 end 设置生成方式 ***/
		try {
			// 查询tableId
			Map<String, Object> params = new HashMap<String, Object>();
			params.put("orgId", ThreadContextHelper.getOrgId());
			params.put("deptId", ThreadContextHelper.getDeptId());
			String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
			// 根据tableId查找表是否为真实表
			String isTrueTable = commTableManagerService.findTableisTureTable(tableId);
			boolean flag = true;
			if ("N".equals(isTrueTable)) {
				flag = false;
			}
			// 张余修改
			// 获取当前多语言类型
			Object lang = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
			String languageCode = "zh_CN";
			if (lang != null) {
				languageCode = lang.toString();
			}
			params.put("languageCode", languageCode);
			params.put("orgCode", orgCode);
			commTableManagerService.updateCbbTabColumns(ccArray, sysId, nodeId, nodeName, tableName, flag, params);// 更新基本字段及实体表信息
			commTableManagerService.updateColOrder(tableId);
			if (null != idSet && !"".equals(idSet) && !"null".equals(idSet)) {
				if ("4".equals(colGeneMethod)) { // 保存组合项的配置信息
					commTableManagerService.saveConfigGroupNew(idSet, groupJson, ThreadContextHelper.getOrgId(), ThreadContextHelper.getDeptId(), sysId);
				} else if ("5".equals(colGeneMethod)) { // 保存统计生成配置信息
					/*** 保存统计生成信息 ***/
					String[] configColumns = new String[3];
					String[] configInput = new String[2];
					String[] orders = new String[3];
					// 统计字段字段名数组
					configColumns[0] = groupSelect1.equals("") ? "" : groupSelect1;
					configColumns[1] = groupSelect2.equals("") ? "" : groupSelect2;
					configColumns[2] = groupSelect3.equals("") ? "" : groupSelect3;
					// 统计字段输入值数组
					configInput[0] = groupInput1.equals("") ? "" : groupInput1;
					configInput[1] = groupInput2.equals("") ? "" : groupInput2;
					// 统计字段顺序数组
					orders[0] = groupSelect1.equals("") ? "" : "1";
					orders[1] = groupSelect2.equals("") ? "" : "2";
					orders[2] = groupSelect3.equals("") ? "" : "3";
					commTableManagerService.saveConfigTJSC(idSet, configColumns, configInput, tableId, ThreadContextHelper.getOrgId(), ThreadContextHelper.getDeptId(), sysId, orders, operation);
				}
			}
			map.put("flag", OpResult.success);
		} catch (Exception e) {
			map.put("flag", OpResult.failure);
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 验证必著
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/checkColIsMust")
	public Map<String,Object> checkColIsMust(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String tableName = request.getParameter("tableName");
		// 查询tableId
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orgId", ThreadContextHelper.getOrgId());
		String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
		// 根据tableId查找表是否为真是表
		String isTrueTable = commTableManagerService.findTableisTureTable(tableId);
		boolean flag = false;// 表中存在数据标示，true：不存在，fasle：存在
		if ("N".equals(isTrueTable)) {
			// 虚拟表永远不存在值
			flag = true;
		} else {
			// 判断该表是否有值
			flag = commTableManagerService.checkColIsMust(tableId);
		}
		if (flag) {
			map.put("flag", OpResult.success);
		} else {
			map.put("mes", "该表已存在数据，【是否必著】不能修改为【是】");
			map.put("flag", OpResult.failure);
		}
		map.put("isTrueTable", isTrueTable);
		return map;
	}

	/**
	 * 导出结构数据
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @throws Exception
	 *             void
	 * @throws
	 */
	@RequestMapping("/exportData")
	public void exportData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		// 填充projects数据
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		ServletOutputStream out = response.getOutputStream();
		BufferedInputStream bis = null;
		BufferedOutputStream bos = null;
		// 获取参数
		String sysId = request.getParameter("sysId");
		String tableName = request.getParameter("tableName");
		String nodeId = request.getParameter("nodeId");
		String isTemplet = request.getParameter("isTemplet");// 是否加载全部字段
																// N：加载基本字段
																// Y：加载全部字段
		String orgId = ThreadContextHelper.getOrgId();
		String deptId = ThreadContextHelper.getDeptId();
		// 调用方法获取tableId
		String tableId = commTableManagerService.getCbbTableId(sysId, tableName);
		try {
			// 获取数据
			List<Map<String, Object>> datas = commTableManagerService.getCbbTabColumnsJiben(orgId, deptId, sysId, nodeId, tableId, isTemplet);
			// 按照页面数据字段展示顺序构造excel文件标题行集合
			List<String> head = new ArrayList<String>();
			head.add("COL_LABEL");
			head.add("COL_NAME");
			head.add("COL_TYPE");
			head.add("COL_LENGTH");
			head.add("COL_DECIMAL");
			head.add("COL_IS_SYS");
			head.add("COL_IS_DISPLAY");
			head.add("COL_IS_MUST");
			head.add("COL_ORDER");
			head.add("REMARK");
			// 创建表头值List
			List<String> headValue = new ArrayList<String>();
			headValue.add("字段中文名");
			headValue.add("字段名");
			headValue.add("字段类型");
			headValue.add("长度");
			headValue.add("小数位数");
			headValue.add("系统字段");
			headValue.add("是否可见");
			headValue.add("是否必著");
			headValue.add("顺序");
			headValue.add("备注");
			// 导出excel
			commTableManagerService.exportData(headValue, head, datas, os);
			byte[] content = os.toByteArray();
			InputStream is = new ByteArrayInputStream(content);
			// 构造文件名
			String fileName = commTableManagerService.getFileName(tableId);
			// 设置response参数，可以打开下载页面
			response.reset();
			response.setContentType("application/vnd.ms-excel");
			response.setHeader("Content-Disposition", "attachment;filename=" + new String((fileName + ".xls").getBytes("GBK"), "iso8859-1"));
			response.setHeader("Content-length", String.valueOf(content.length));
			bis = new BufferedInputStream(is);
			bos = new BufferedOutputStream(out);
			byte[] buff = new byte[2048];
			int bytesRead = 0;
			while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
				bos.write(buff, 0, bytesRead);
			}
			bos.flush();
			out.flush();
		} catch (IOException e) {
			e.printStackTrace();
			throw e;
		} finally {
			if (bis != null) {
				bis.close();
			}
			if (bos != null) {
				bos.close();
			}
			if (out != null) {
				out.close();
			}
		}
	}

	/**
	 * 导出结构模板
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @throws Exception
	 *             void
	 * @throws
	 */
	@RequestMapping("/exportExcelMoudle")
	public void exportExcelMoudle(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		ServletOutputStream out = response.getOutputStream();
		BufferedInputStream bis = null;
		BufferedOutputStream bos = null;
		// 创建表头值List
		List<String> headValue = new ArrayList<String>();
		headValue.add("字段中文名");
		headValue.add("字段名");
		headValue.add("字段类型");
		headValue.add("长度");
		headValue.add("小数位数");
		headValue.add("系统字段");
		headValue.add("是否可见");
		headValue.add("是否必著");
		headValue.add("顺序");
		headValue.add("备注");
		try {
			// 导出excel
			commTableManagerService.exportExcelModule(headValue, os);
			byte[] content = os.toByteArray();
			InputStream is = new ByteArrayInputStream(content);
			// 设置response参数，可以打开下载页面
			response.reset();
			response.setContentType("application/vnd.ms-excel");
			response.setHeader("Content-Disposition", "attachment;filename=" + new String(("模板.xls").getBytes("GBK"), "iso8859-1"));
			response.setHeader("Content-length", String.valueOf(content.length));
			bis = new BufferedInputStream(is);
			bos = new BufferedOutputStream(out);
			byte[] buff = new byte[2048];
			int bytesRead = 0;
			while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
				bos.write(buff, 0, bytesRead);
			}
			bos.flush();
			out.flush();
		} catch (IOException e) {
			e.printStackTrace();
			throw e;
		} finally {
			if (bis != null) {
				bis.close();
			}
			if (bos != null) {
				bos.close();
			}
			if (out != null) {
				out.close();
			}
		}
	}

	/**
	 * 导入excel文件
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/importData")
	public ModelAndView importData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView();
		// 获取参数
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String tableName = request.getParameter("tableName");
		String nodeId = request.getParameter("nodeId");
		String nodeName = request.getParameter("nodeName");
		String dialogId = request.getParameter("dialogId");
		String isTrueTable = request.getParameter("isTrueTable");
		mav.addObject("dialogId", dialogId);
		// 查询tableId
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orgId", ThreadContextHelper.getOrgId());
		String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
		MultipartHttpServletRequest mulRequest = (MultipartHttpServletRequest) request;
		// String logoPathDir = "files/structureImportFiles";
		/** 得到图片保存目录的真实路径 **/
		String logoRealPathDir = mulRequest.getSession().getServletContext().getRealPath("/");
		if (!logoRealPathDir.endsWith(File.separator)) {
			logoRealPathDir = logoRealPathDir + File.separator;
		}
		logoRealPathDir = logoRealPathDir + "files";
		/** 根据真实路径创建目录 **/
		File logoSaveFile = new File(logoRealPathDir);
		if (!logoSaveFile.exists()) {
			logoSaveFile.mkdirs();
		}
		/** 页面控件的文件流 **/
		MultipartFile multipartFile = mulRequest.getFile("file");
		String fileName = multipartFile.getOriginalFilename();
		/** 拼成完整的文件保存路径加文件 **/
		String filePath = logoRealPathDir + File.separator + SessionHelper.getLoginSysUserId(request) + "_" + System.currentTimeMillis() + "_" + fileName;
		File file = new File(filePath);
		/** 解析Excel数据 **/
		Map<String, Vector<Vector<String>>> excelData = null; // 解析文件后数据
		try {
			// 判断文件类型，调用方法解析excel文件
			if (filePath.endsWith(".xls")) {
				// 解析2003excel文件
				multipartFile.transferTo(file);
				excelData = commTableManagerService.readXls(filePath);
			} else {
				// 解析2007excel文件
				multipartFile.transferTo(file);
				excelData = commTableManagerService.readXlsx(filePath);
			}
			mav.addObject("sysId", sysId);
			mav.addObject("tableName", tableName);
			mav.addObject("nodeId", nodeId);
			mav.addObject("nodeName", nodeName);
			mav.addObject("avicit/cbb/techclass/tabledefine/commtablemanager/table_structure_import");
			if (!excelData.isEmpty()) {
				if (excelData.containsKey("sheetNames")) {
					Vector<String> vector = excelData.get("sheetNames").get(0);
					for (int i = 0; i < vector.size(); i++) {
						// 获取表名
						String sheetName = vector.get(i);
						// 根据表名获取表中的数据集合
						Vector<Vector<String>> datas = excelData.get(sheetName);
						// 调用方法验证数据
						commTableManagerService.testExcel(datas, tableId);
						// 调用方法添加
						commTableManagerService.insertFromExcel(datas, sysId, nodeId, nodeName, tableName, ThreadContextHelper.getOrgId(), ThreadContextHelper.getDeptId(), SessionHelper.getLoginSysUserId(request), RequestUtil.getClientIp(request), isTrueTable);
					}
				}
			}
			request.setAttribute("message", "导入成功！");
		} catch (Exception e) {
			request.setAttribute("message", e.getMessage());
			e.printStackTrace();
		} finally {
			// 导入完成删除该文件
			file.delete();
		}
		return mav;
	}

	/**
	 * 获取列最大排序值
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/getColMaxOrder")
	public ModelAndView getColMaxOrder(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView("");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String tableName = request.getParameter("tableName");
		// 查询tableId
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orgId", SessionHelper.getCurrentOrgId(request));
		String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
		// 判断该表是否有值
		int num = commTableManagerService.selectMaxOrder(tableId);
		mav.addObject("num", num);
		mav.setView(null);
		return mav;
	}

	/**
	 * 代码维护模块,导出结构模板
	 *
	 * @author 郭亮
	 * @param request
	 * @param response
	 * @throws Exception
	 *             void
	 * @throws
	 */
	@RequestMapping("/colCodeExportExcelMoudle")
	public void colCodeExportExcelMoudle(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		ServletOutputStream out = response.getOutputStream();
		BufferedInputStream bis = null;
		BufferedOutputStream bos = null;
		// 创建表头值List
		List<String> headValue = new ArrayList<String>();
		headValue.add("顺序");
		headValue.add("显示值");
		headValue.add("真实值");
		headValue.add("是否有效");
		try {
			// 导出excel
			commTableManagerService.exportExcelModule(headValue, os);
			byte[] content = os.toByteArray();
			InputStream is = new ByteArrayInputStream(content);
			// 设置response参数，可以打开下载页面
			response.reset();
			response.setContentType("application/vnd.ms-excel");
			response.setHeader("Content-Disposition", "attachment;filename=" + new String(("代码维护模板.xls").getBytes("GBK"), "iso8859-1"));
			response.setHeader("Content-length", String.valueOf(content.length));
			bis = new BufferedInputStream(is);
			bos = new BufferedOutputStream(out);
			byte[] buff = new byte[2048];
			int bytesRead = 0;
			while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
				bos.write(buff, 0, bytesRead);
			}
			bos.flush();
			out.flush();
		} catch (IOException e) {
			e.printStackTrace();
			throw e;
		} finally {
			if (bis != null) {
				bis.close();
			}
			if (bos != null) {
				bos.close();
			}
			if (out != null) {
				out.close();
			}
		}
	}

	/**
	 * 代码维护模块,导入excel文件
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/colCodeImportData")
	public ModelAndView colCodeIimportData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView("");
		// 获取参数
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String tableName = request.getParameter("tableName");
		String nodeId = request.getParameter("nodeId");
		String nodeName = request.getParameter("nodeName");
		String cid = request.getParameter("cid");
		String dialogId = request.getParameter("dialogId");
		mav.addObject("dialogId", dialogId);
		// 查询tableId
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orgId", SessionHelper.getCurrentOrgId(request));
		String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
		MultipartHttpServletRequest mulRequest = (MultipartHttpServletRequest) request;
		// String logoPathDir = "files/colCodeImportFiles";
		/** 得到图片保存目录的真实路径 **/
		String logoRealPathDir = mulRequest.getSession().getServletContext().getRealPath("/");
		if (!logoRealPathDir.endsWith(File.separator)) {
			logoRealPathDir = logoRealPathDir + File.separator;
		}
		logoRealPathDir = logoRealPathDir + "files";
		/** 根据真实路径创建目录 **/
		File logoSaveFile = new File(logoRealPathDir);
		if (!logoSaveFile.exists()) {
			logoSaveFile.mkdirs();
		}
		/** 页面控件的文件流 **/
		MultipartFile multipartFile = mulRequest.getFile("file");
		String fileName = multipartFile.getOriginalFilename();
		/** 拼成完整的文件保存路径加文件 **/
		String filePath = logoRealPathDir + File.separator + SessionHelper.getLoginSysUserId(request) + "_" + System.currentTimeMillis() + "_" + fileName;
		File file = new File(filePath);
		/** 解析Excel数据 **/
		Map<String, Vector<Vector<String>>> excelData = null; // 解析文件后数据
		try {
			// 判断文件类型，调用方法解析excel文件
			if (filePath.endsWith(".xls")) {
				// 解析2003excel文件
				multipartFile.transferTo(file);
				excelData = commTableManagerService.readXls(filePath);
			} else {
				// 解析2007excel文件
				multipartFile.transferTo(file);
				excelData = commTableManagerService.readXlsx(filePath);
			}
			mav.addObject("sysId", sysId);
			mav.addObject("tableName", tableName);
			mav.addObject("nodeId", nodeId);
			mav.addObject("nodeName", nodeName);
			mav.setViewName("avicit/cbb/techclass/tabledefine/commtablemanager/table_col_code_import");
			if (!excelData.isEmpty()) {
				if (excelData.containsKey("sheetNames")) {
					Vector<String> vector = excelData.get("sheetNames").get(0);
					for (int i = 0; i < vector.size(); i++) {
						// 获取excel表名
						String sheetName = vector.get(i);
						// 根据excel表名获取表中的数据集合
						Vector<Vector<String>> datas = excelData.get(sheetName);
						// 调用方法验证数据
						commTableManagerService.testColCodeExcel(datas, cid);
						// 调用方法添加数据
						commTableManagerService.inserColCodetFromExcel(datas, SessionHelper.getCurrentOrgId(request), SessionHelper.getCurrentDeptId(request), sysId, cid, tableId);
					}
				}
			}
			request.setAttribute("message", "导入成功！");
		} catch (Exception e) {
			request.setAttribute("message", e.getMessage());
			e.printStackTrace();
		} finally {
			// 导入完成删除该文件
			file.delete();
		}
		return mav;
	}

	/***
	 * 判断字段是否可以配置统计生成（著录定义页面生成方式配置判断方法）
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/ckeckGeneMethod")
	@ResponseBody
	public Map<String,Object> ckeckGeneMethod(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String sysId = request.getParameter("sysId");
		String tableName = request.getParameter("tableName");
		// 查询tableId
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orgId", ThreadContextHelper.getOrgId());
		String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
		String nodeId = request.getParameter("nodeId");
		// 根据nodeId判断，1、是否为2级节点2、该字段是否为案卷级表中的字段
		boolean isSecond = commTableManagerService.checkNodeIsSecond(nodeId);
		if (isSecond) {
			boolean isAJJ = commTableManagerService.checkTabIsAJJ(tableId, nodeId);
			if (isAJJ) {
				map.put("flag", "success");
			} else {
				map.put("flag", "failure");
			}
		} else {
			map.put("flag", "failure");
		}
		return map;
	}

	/**
	 * 配置设置页面初始化
	 *
	 * @author 郭亮
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/toConfigSet")
	public ModelAndView toConfigSet(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView();
		String id = request.getParameter("id");
		String dialogId = request.getParameter("dialogId");
		String toJspUrl = request.getParameter("toJspUrl");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String nodeId = request.getParameter("nodeId");
		String nodeName = request.getParameter("nodeName");
		String tableName = request.getParameter("tableName");
		String colGeneMethodSelect = request.getParameter("lookupCode");// 用户当前选择的生成方式
		CbbTabColumns cbbTabcolumns = commTableManagerService.getCbbTabColumnsById(id);
		String dropdownType = cbbTabcolumns.getColDropdownType();
		String colGeneMethod = cbbTabcolumns.getColGeneMethod();
		String colLength = String.valueOf(cbbTabcolumns.getColLength());
		String colGeneMethodRule = cbbTabcolumns.getColGeneMethodRule();
		String colType = cbbTabcolumns.getColType();
		// 构造json串
		String colCode = "";
		String lyerType = commTableManagerService.getTabLayerType(nodeId); // 双层结构类型(0：案卷，1：盒)
		if ("1".equals(dropdownType)) { // 参选
			if ("1".equals(colGeneMethodSelect)) { // 默认值
				// 查找通用代码,并拼成json串
				List<Object[]> colCodeList = commTableManagerService.getLookupCodeByColumnId(id);
				boolean flag = false;
				if (colCodeList.size() > 0) {
					colCode = "[";
					for (int j = 0; j < colCodeList.size(); j++) {
						String lookupName = String.valueOf(colCodeList.get(j)[0]);// 显示值
						String lookupCode = String.valueOf(colCodeList.get(j)[1]);// 真实值
						colCode = colCode + "{'lookupName' : '" + lookupName + "','lookupCode' : '" + lookupCode + "'},";
						if (lookupCode.equals(colGeneMethodRule)) { // 参选配置在通用代码中包含
							flag = true;
						}
					}
					if (!flag) { // 参选配置信息不在通用代码里(手动输入)
						// 将这个配置信息作为通用代码中的一个对象添加到json串中
						colCode = colCode + "{'lookupName' : '" + colGeneMethodRule + "','lookupCode' : '" + colGeneMethodRule + "'},";
					}
					colCode = colCode.substring(0, colCode.length() - 1);
					colCode = colCode + "]";
				}
				// 默认值时向页面传第一个空的jsonArray(由于组合项配置时需要该参数,默认值配置时不传该参数会报错)
				mav.addObject("configJa", "[]");
			} else if ("4".equals(colGeneMethodSelect)) {
				// 查找可组合字段
				String initColNameStr = commTableManagerService.getColNmaeByColType(cbbTabcolumns.getTableId(), cbbTabcolumns.getColType(), cbbTabcolumns.getId(), ThreadContextHelper.getOrgId(), ThreadContextHelper.getDeptId(), sysId, nodeId);
				mav.addObject("initColNameStr", initColNameStr);
				// 获取字段配置信息
				String configJson = commTableManagerService.getGroupConfigNew(id);
				JSONArray configJa = JSONArray.fromObject(configJson);
				mav.addObject("configJa", configJa);
				/*
				 * Map<String, Object> map = commTableManagerService .getGroupConfig(id); String select1 = map.get("1") == null ? "" : map.get("1") .toString(); String input1 =
				 * map.get("2") == null ? "" : map.get("2") .toString(); String select2 = map.get("3") == null ? "" : map.get("3") .toString(); String input2 = map.get("4") == null
				 * ? "" : map.get("4") .toString(); String select3 = map.get("5") == null ? "" : map.get("5") .toString(); mav.addObject("select1", select1);
				 * mav.addObject("input1", input1); mav.addObject("select2", select2); mav.addObject("input2", input2); mav.addObject("select3", select3);
				 */
			} else if ("5".equals(colGeneMethodSelect)) { // 统计生成
				String config = ""; // 完整的配置信息
				String operation = ""; // 运算方式
				String describtion = ""; // 完整的中文描述
				String describtionEnd = ""; // 部分中文描述，用于页面填值
				// 根据字段ID查找字段的配置信息
				List<String> configList = commTableManagerService.getTjscConfigformanager(id);
				if (configList.size() > 0) {
					config = configList.get(0);
					operation = configList.get(1);
					String operationTitle = "";
					if ("1".equals(operation)) {
						operationTitle = "第一个";
					} else if ("2".equals(operation)) {
						operationTitle = "最后一个";
					} else if ("3".equals(operation)) {
						operationTitle = "最大的";
					} else if ("4".equals(operation)) {
						operationTitle = "最小的";
					} else if ("5".equals(operation)) {
						operationTitle = "求和";
					}
					describtionEnd = configList.get(2);
					if ("0".equals(lyerType)) {
						describtion = "[案卷级的]" + cbbTabcolumns.getColLabel() + ":=" + operationTitle + configList.get(2);
					} else if ("1".equals(lyerType)) {
						describtion = "[盒级的]" + cbbTabcolumns.getColLabel() + ":=" + operationTitle + configList.get(2);
					}
				}
				Map<String, Object> map = commTableManagerService.getTjscConfig(id);
				String select1 = map.get("1") == null ? "" : map.get("1").toString();
				String input1 = map.get("2") == null ? "" : map.get("2").toString();
				String select2 = map.get("3") == null ? "" : map.get("3").toString();
				String input2 = map.get("4") == null ? "" : map.get("4").toString();
				String select3 = map.get("5") == null ? "" : map.get("5").toString();
				mav.addObject("select1", select1);
				mav.addObject("input1", input1);
				mav.addObject("select2", select2);
				mav.addObject("input2", input2);
				mav.addObject("select3", select3);
				mav.addObject("config", config);
				mav.addObject("operation", operation);
				mav.addObject("describtion", describtion); // 页面初始化中文描述完整字符串
				mav.addObject("title", "[案卷级的]" + cbbTabcolumns.getColLabel()); // 页面中文描述部分字符串，用于选择了运算符后重新填值
				mav.addObject("describtionEdit", describtionEnd); // 页面中文描述部分字符串，用于选择了运算符后重新填值
				if (colGeneMethodSelect.equals(colGeneMethod)) { // 旧的配置不是统计生成时不能将生成方式值传到页面
					mav.addObject("colGeneMethodRule", cbbTabcolumns.getColGeneMethodRule());
				}
			}
		} else if ("2".equals(dropdownType)) { // 只选
			// 查找通用代码
			// 获取该字段通用代码集合
			List<Object[]> colCodeList = commTableManagerService.getLookupCodeByColumnId(id);
			if (colCodeList.size() > 0) {
				colCode = "[";
				for (int j = 0; j < colCodeList.size(); j++) {
					String lookupName = String.valueOf(colCodeList.get(j)[0]);// 显示值
					String lookupCode = String.valueOf(colCodeList.get(j)[1]);// 真实值
					colCode = colCode + "{'lookupName' : '" + lookupName + "','lookupCode' : '" + lookupCode + "'},";
				}
				colCode = colCode.substring(0, colCode.length() - 1);
				colCode = colCode + "]";
			}
			// 默认值时向页面传第一个空的jsonArray(由于组合项配置时需要该参数,默认值配置时不传该参数会报错)
			mav.addObject("configJa", "[]");
			/******* 2015/07/23新增 - 郭亮（统计生成） ***********/
			if ("5".equals(colGeneMethodSelect)) { // 统计生成
				String config = ""; // 完整的配置信息
				String operation = ""; // 运算方式
				String describtion = ""; // 完整的中文描述
				String describtionEnd = ""; // 部分中文描述，用于页面填值
				// 根据字段ID查找字段的配置信息
				List<String> configList = commTableManagerService.getTjscConfigformanager(id);
				if (configList.size() > 0) {
					config = configList.get(0);
					operation = configList.get(1);
					String operationTitle = "";
					if ("1".equals(operation)) {
						operationTitle = "第一个";
					} else if ("2".equals(operation)) {
						operationTitle = "最后一个";
					} else if ("3".equals(operation)) {
						operationTitle = "最大的";
					} else if ("4".equals(operation)) {
						operationTitle = "最小的";
					} else if ("5".equals(operation)) {
						operationTitle = "求和";
					}
					describtionEnd = configList.get(2);
					if ("0".equals(lyerType)) {
						describtion = "[案卷级的]" + cbbTabcolumns.getColLabel() + ":=" + operationTitle + configList.get(2);
					} else if ("1".equals(lyerType)) {
						describtion = "[盒级的]" + cbbTabcolumns.getColLabel() + ":=" + operationTitle + configList.get(2);
					}
				}
				Map<String, Object> map = commTableManagerService.getTjscConfig(id);
				String select1 = map.get("1") == null ? "" : map.get("1").toString();
				String input1 = map.get("2") == null ? "" : map.get("2").toString();
				String select2 = map.get("3") == null ? "" : map.get("3").toString();
				String input2 = map.get("4") == null ? "" : map.get("4").toString();
				String select3 = map.get("5") == null ? "" : map.get("5").toString();
				mav.addObject("select1", select1);
				mav.addObject("input1", input1);
				mav.addObject("select2", select2);
				mav.addObject("input2", input2);
				mav.addObject("select3", select3);
				mav.addObject("config", config);
				mav.addObject("operation", operation);
				mav.addObject("describtion", describtion); // 页面初始化中文描述完整字符串
				mav.addObject("title", "[案卷级的]" + cbbTabcolumns.getColLabel()); // 页面中文描述部分字符串，用于选择了运算符后重新填值
				mav.addObject("describtionEdit", describtionEnd); // 页面中文描述部分字符串，用于选择了运算符后重新填值
				if (colGeneMethodSelect.equals(colGeneMethod)) { // 旧的配置不是统计生成时不能将生成方式值传到页面
					mav.addObject("colGeneMethodRule", cbbTabcolumns.getColGeneMethodRule());
				}
			}
			/******* 2015/07/23新增 - 郭亮（统计生成） ***********/
		} else if ("3".equals(dropdownType)) { // 选择
			// 默认值时向页面传第一个空的jsonArray(由于组合项配置时需要该参数,默认值配置时不传该参数会报错)
			mav.addObject("configJa", "[]");
			String colRuleName = cbbTabcolumns.getColRuleName();
			mav.addObject("colRuleName", colRuleName);
			if (null != colGeneMethodRule) {
				if ("user".equals(colRuleName)) {
					/*
					 * // 根据colGeneMethodRule查找userName String userName = commTableManagerService .getUserNameById(colGeneMethodRule); mav.addObject("userName", userName);
					 */
					// 构造json串
					colCode = "[{\"lookupName\" : \"当前用户\",\"lookupCode\" : \"currentUser\"}]";
				} else if ("dept".equals(colRuleName)) {
					/*
					 * String deptName = commTableManagerService .getDeptNameById(colGeneMethodRule); mav.addObject("deptName", deptName);
					 */
					// 构造json串
					colCode = "[{\"lookupName\" : \"当前部门\",\"lookupCode\" : \"currentDept\"},";
					colCode = colCode + "{\"lookupName\" : \"当前上级部门\",\"lookupCode\" : \"parentDept\"}]";
				} else if ("custom".equals(colRuleName)) {
					String customPath = cbbTabcolumns.getCustomPath();
					String customName = commTableManagerService.getCustomValue(colGeneMethodRule, customPath);
					mav.addObject("customPath", customPath);
					mav.addObject("customName", customName);
				}
			}
			/******* 2015/07/23新增 - 郭亮（统计生成） ***********/
			if ("5".equals(colGeneMethodSelect)) { // 统计生成
				String config = ""; // 完整的配置信息
				String operation = ""; // 运算方式
				String describtion = ""; // 完整的中文描述
				String describtionEnd = ""; // 部分中文描述，用于页面填值
				// 根据字段ID查找字段的配置信息
				List<String> configList = commTableManagerService.getTjscConfigformanager(id);
				if (configList.size() > 0) {
					config = configList.get(0);
					operation = configList.get(1);
					String operationTitle = "";
					if ("1".equals(operation)) {
						operationTitle = "第一个";
					} else if ("2".equals(operation)) {
						operationTitle = "最后一个";
					} else if ("3".equals(operation)) {
						operationTitle = "最大的";
					} else if ("4".equals(operation)) {
						operationTitle = "最小的";
					} else if ("5".equals(operation)) {
						operationTitle = "求和";
					}
					describtionEnd = configList.get(2);
					if ("0".equals(lyerType)) {
						describtion = "[案卷级的]" + cbbTabcolumns.getColLabel() + ":=" + operationTitle + configList.get(2);
					} else if ("1".equals(lyerType)) {
						describtion = "[盒级的]" + cbbTabcolumns.getColLabel() + ":=" + operationTitle + configList.get(2);
					}
				}
				Map<String, Object> map = commTableManagerService.getTjscConfig(id);
				String select1 = map.get("1") == null ? "" : map.get("1").toString();
				String input1 = map.get("2") == null ? "" : map.get("2").toString();
				String select2 = map.get("3") == null ? "" : map.get("3").toString();
				String input2 = map.get("4") == null ? "" : map.get("4").toString();
				String select3 = map.get("5") == null ? "" : map.get("5").toString();
				mav.addObject("select1", select1);
				mav.addObject("input1", input1);
				mav.addObject("select2", select2);
				mav.addObject("input2", input2);
				mav.addObject("select3", select3);
				mav.addObject("config", config);
				mav.addObject("operation", operation);
				mav.addObject("describtion", describtion); // 页面初始化中文描述完整字符串
				mav.addObject("title", "[案卷级的]" + cbbTabcolumns.getColLabel()); // 页面中文描述部分字符串，用于选择了运算符后重新填值
				mav.addObject("describtionEdit", describtionEnd); // 页面中文描述部分字符串，用于选择了运算符后重新填值
				if (colGeneMethodSelect.equals(colGeneMethod)) { // 旧的配置不是统计生成时不能将生成方式值传到页面
					mav.addObject("colGeneMethodRule", cbbTabcolumns.getColGeneMethodRule());
				}
			}
			/******* 2015/07/23新增 - 郭亮（统计生成） ***********/
		} else { // 普通字段，类型，长度
			if ("1".equals(colGeneMethodSelect)) { // 默认值
				if ("string".equals(colType) || "colb".equals(colType)) {
					// 构造json串
					colCode = "[{\"lookupName\" : \"当前用户\",\"lookupCode\" : \"currentUser\"},";
					colCode = colCode + "{\"lookupName\" : \"当前部门ID\",\"lookupCode\" : \"currentDeptId\"},";
					colCode = colCode + "{\"lookupName\" : \"当前部门名称\",\"lookupCode\" : \"currentDeptName\"},";
					colCode = colCode + "{\"lookupName\" : \"当前组织代码\",\"lookupCode\" : \"currentOrg\"},";
					colCode = colCode + "{\"lookupName\" : \"当前全宗名称\",\"lookupCode\" : \"currentQzName\"},";
					colCode = colCode + "{\"lookupName\" : \"当前全宗代码\",\"lookupCode\" : \"currentQzCode\"},";
					colCode = colCode + "{\"lookupName\" : \"当前数据节点属性\",\"lookupCode\" : \"currentNodeRemark\"},";
					colCode = colCode + "{\"lookupName\" : \"当前上级部门名称\",\"lookupCode\" : \"parentDeptName\"},";
					colCode = colCode + "{\"lookupName\" : \"当前上级部门ID\",\"lookupCode\" : \"parentDeptId\"},";
					colCode = colCode + "{\"lookupName\" : \"当前上级部门代码\",\"lookupCode\" : \"parentDeptCode\"}]";
				} else if ("date".equals(colType)) {
					// 构造json串
					colCode = "[{\"lookupName\" : \"当前时间\",\"lookupCode\" : \"currentDate\"}]";
				} else if ("float".equals(colType)) { // 浮点型字段，小数位数
					String colDecimal = String.valueOf(cbbTabcolumns.getColDecimal());
					mav.addObject("colDecimal", colDecimal);
				}
				// 默认值时向页面传第一个空的jsonArray(由于组合项配置时需要该参数,默认值配置时不传该参数会报错)
				mav.addObject("configJa", "[]");
			} else if ("4".equals(colGeneMethodSelect)) {
				// 查找可组合字段
				String initColNameStr = commTableManagerService.getColNmaeByColType(cbbTabcolumns.getTableId(), cbbTabcolumns.getColType(), cbbTabcolumns.getId(), SessionHelper.getCurrentOrgId(request), SessionHelper.getCurrentDeptId(request), sysId, nodeId);
				mav.addObject("initColNameStr", initColNameStr);
				// 获取字段配置信息
				String configJson = commTableManagerService.getGroupConfigNew(id);
				JSONArray configJa = JSONArray.fromObject(configJson);
				mav.addObject("configJa", configJa);
			} else if ("5".equals(colGeneMethodSelect)) { // 统计生成
				String config = ""; // 完整的配置信息
				String operation = ""; // 运算方式
				String describtion = ""; // 完整的中文描述
				String describtionEnd = ""; // 部分中文描述，用于页面填值
				// 根据字段ID查找字段的配置信息
				List<String> configList = commTableManagerService.getTjscConfigformanager(id);
				if (configList.size() > 0) {
					config = configList.get(0);
					operation = configList.get(1);
					String operationTitle = "";
					if ("1".equals(operation)) {
						operationTitle = "第一个";
					} else if ("2".equals(operation)) {
						operationTitle = "最后一个";
					} else if ("3".equals(operation)) {
						operationTitle = "最大的";
					} else if ("4".equals(operation)) {
						operationTitle = "最小的";
					} else if ("5".equals(operation)) {
						operationTitle = "求和";
					}
					describtionEnd = configList.get(2);
					if ("0".equals(lyerType)) {
						describtion = "[案卷级的]" + cbbTabcolumns.getColLabel() + ":=" + operationTitle + configList.get(2);
					} else if ("1".equals(lyerType)) {
						describtion = "[盒级的]" + cbbTabcolumns.getColLabel() + ":=" + operationTitle + configList.get(2);
					}
				}
				Map<String, Object> map = commTableManagerService.getTjscConfig(id);
				String select1 = map.get("1") == null ? "" : map.get("1").toString();
				String input1 = map.get("2") == null ? "" : map.get("2").toString();
				String select2 = map.get("3") == null ? "" : map.get("3").toString();
				String input2 = map.get("4") == null ? "" : map.get("4").toString();
				String select3 = map.get("5") == null ? "" : map.get("5").toString();
				mav.addObject("select1", select1);
				mav.addObject("input1", input1);
				mav.addObject("select2", select2);
				mav.addObject("input2", input2);
				mav.addObject("select3", select3);
				mav.addObject("config", config);
				mav.addObject("operation", operation);
				mav.addObject("describtion", describtion); // 页面初始化中文描述完整字符串
				if ("0".equals(lyerType)) {
					mav.addObject("title", "[案卷级的]" + cbbTabcolumns.getColLabel()); // 页面中文描述部分字符串，用于选择了运算符后重新填值
				} else if ("1".equals(lyerType)) {
					mav.addObject("title", "[盒级的]" + cbbTabcolumns.getColLabel()); // 页面中文描述部分字符串，用于选择了运算符后重新填值
				}
				mav.addObject("describtionEdit", describtionEnd); // 页面中文描述部分字符串，用于选择了运算符后重新填值
				if (colGeneMethodSelect.equals(colGeneMethod)) { // 旧的配置不是统计生成时不能将生成方式值传到页面
					mav.addObject("colGeneMethodRule", cbbTabcolumns.getColGeneMethodRule());
				}
			}
		}
		if (!"".equals(colCode)) {
			JSONArray codeJson = JSONArray.fromObject(colCode);
			mav.addObject("initCode", codeJson);
		} else {
			mav.addObject("initCode", "[]");
		}
		mav.addObject("cbbTabcolumns", cbbTabcolumns);
		mav.addObject("dialogId", dialogId);
		mav.addObject("sysId", sysId);
		mav.addObject("nodeId", nodeId);
		mav.addObject("nodeName", nodeName);
		mav.addObject("tableName", tableName);
		mav.addObject("dropdownType", dropdownType);
		mav.addObject("colGeneMethod", colGeneMethod);
		mav.addObject("colLength", colLength);
		mav.addObject("colDecimal", String.valueOf(cbbTabcolumns.getColDecimal()));
		mav.addObject("colType", colType);
		mav.addObject("colGeneMethodSelect", colGeneMethodSelect);
		mav.setViewName(toJspUrl);
		return mav;
	}

	@RequestMapping("/toConfigJspForShunDai")
	public ModelAndView toConfigJspForShunDai(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView();
		String dialogId = request.getParameter("dialogId");
		String sysId = request.getParameter("sysId");
		String columnId = request.getParameter("id");
		String nodeId = request.getParameter("nodeId");
		CbbTabColumns cbbTabcolumns = commTableManagerService.getCbbTabColumnsById(columnId);
		String tableId = cbbTabcolumns.getTableId();
//		String dropdownType = cbbTabcolumns.getColDropdownType();
//		String colGeneMethod = cbbTabcolumns.getColGeneMethod();
//		String colLength = String.valueOf(cbbTabcolumns.getColLength());
//		String colGeneMethodRule = cbbTabcolumns.getColGeneMethodRule();
		String colType = cbbTabcolumns.getColType();
		// 构造json串
		String initColNameStr = commTableManagerService.getColNmaeByColTypeIncidentally(tableId, colType, columnId, ThreadContextHelper.getOrgId(), ThreadContextHelper.getDeptId(), sysId, nodeId);
		mav.addObject("initColNameStr", initColNameStr);
		mav.addObject("dialogId", dialogId);
		mav.addObject("cbbTabcolumns", cbbTabcolumns);
		mav.setViewName("avicit/cbb/techclass/tabledefine/commtablemanager/table_node_record_set_incidentally");
		return mav;
	}

	/***
	 * 统计生成编辑页面初始化
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toTjscSet")
	public ModelAndView toTjscSet(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView();
		String id = request.getParameter("id");
		String dialogId = request.getParameter("dialogId");
		String toJspUrl = request.getParameter("toJspUrl");
		String operation = request.getParameter("operation");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String nodeId = request.getParameter("nodeId");
		String lyerType = commTableManagerService.getTabLayerType(nodeId); // 双层结构类型(0：案卷，1：盒)
		String tableName = request.getParameter("tableName");
		CbbTabColumns cbbTabcolumns = commTableManagerService.getCbbTabColumnsById(id);
		// String dropdownType = cbbTabcolumns.getColDropdownType();
		String colLength = String.valueOf(cbbTabcolumns.getColLength());
		String colType = cbbTabcolumns.getColType();
		// 根据字段ID查找字段的配置信息(用于页面显示)
		String config = "";
		List<String> configList = commTableManagerService.getTjscConfigformanager(id);
		if (configList.size() > 0) {
			config = configList.get(0);
		}
		if ("0".equals(lyerType)) {
			config = "案卷级." + cbbTabcolumns.getColLabel() + ":=" + config;
		} else if ("1".equals(lyerType)) {
			config = "盒级." + cbbTabcolumns.getColLabel() + ":=" + config;
		}
		// 查找可组合字段构造下拉列表数据
		String initColNameStr = commTableManagerService.getColNameByColTypeForTJSC(cbbTabcolumns.getTableId(), cbbTabcolumns.getColType(), cbbTabcolumns.getId(), SessionHelper.getCurrentOrgId(request), SessionHelper.getCurrentDeptId(request), sysId, nodeId);
		// 根据字段ID获取组合项配置信息(用于控件初始化)
		Map<String, Object> map = commTableManagerService.getTjscConfig(id);
		String select1 = map.get("1") == null ? "" : map.get("1").toString();
		String input1 = map.get("2") == null ? "" : map.get("2").toString();
		String select2 = map.get("3") == null ? "" : map.get("3").toString();
		String input2 = map.get("4") == null ? "" : map.get("4").toString();
		String select3 = map.get("5") == null ? "" : map.get("5").toString();
		// 将运算符转换成中文
		if ("1".equals(operation)) {
			operation = "第一个";
		} else if ("2".equals(operation)) {
			operation = "最后一个";
		} else if ("3".equals(operation)) {
			operation = "最大的";
		} else if ("4".equals(operation)) {
			operation = "最小的";
		} else if ("5".equals(operation)) {
			operation = "求和";
		}
		mav.addObject("dialogId", dialogId);
		mav.addObject("sysId", sysId);
		mav.addObject("nodeId", nodeId);
		mav.addObject("tableName", tableName);
		mav.addObject("select1", select1);
		mav.addObject("input1", input1);
		mav.addObject("select2", select2);
		mav.addObject("input2", input2);
		mav.addObject("select3", select3);
		mav.addObject("initColNameStr", initColNameStr);
		mav.addObject("cbbTabcolumns", cbbTabcolumns);
		mav.addObject("colLength", colLength);
		mav.addObject("colType", colType);
		mav.addObject("config", config);// 编辑页面描述信息初始化时的字符串
		if ("0".equals(lyerType)) {
			mav.addObject("title", "案卷级." + cbbTabcolumns.getColLabel());// 用于编辑页面拼接描述规则
		} else if ("1".equals(lyerType)) {
			mav.addObject("title", "盒级." + cbbTabcolumns.getColLabel());// 用于编辑页面拼接描述规则
		}
		if ("0".equals(lyerType)) {
			mav.addObject("parentTitle", "[案卷级的]" + cbbTabcolumns.getColLabel());// 用于编辑页面拼接中文描述并向显示页面传递
		} else if ("1".equals(lyerType)) {
			mav.addObject("parentTitle", "[盒级的]" + cbbTabcolumns.getColLabel());// 用于编辑页面拼接中文描述并向显示页面传递
		}
		mav.addObject("operation", operation);// 用于编辑页面拼接规则描述
		mav.setViewName(toJspUrl);
		return mav;
	}

	/**
	 * 判断配置合法性
	 *
	 * @author 郭亮
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/checkConfig")
	public Map<String,Object> checkConfig(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String id = request.getParameter("id");
		String tableName = request.getParameter("tableName");
		String sysId = request.getParameter("sysId");
		String nodeId = request.getParameter("nodeId");
		String colGeneMethod = request.getParameter("colGeneMethod");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orgId", ThreadContextHelper.getOrgId());
		String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
		CbbTabColumns cbbTabcolumns = commTableManagerService.getCbbTabColumnsById(id);
		String dropdownType = cbbTabcolumns.getColDropdownType();
		String colRuleName = cbbTabcolumns.getColRuleName();
		String colType = cbbTabcolumns.getColType();
		try {
			if ("1".equals(dropdownType)) { // 参选
				if ("1".equals(colGeneMethod)) { // 默认值
					// 获取该字段通用代码集合
					List<Object[]> colCodeList = commTableManagerService.getLookupCodeByColumnId(id);
					// 构造json串
					String colCode = "";
					if (colCodeList.size() > 0) {
						colCode = colCode + "[";
						for (int j = 0; j < colCodeList.size(); j++) {
							String lookupName = String.valueOf(colCodeList.get(j)[0]);// 显示值
							String lookupCode = String.valueOf(colCodeList.get(j)[1]);// 真实值
							colCode = colCode + "{\"lookupName\" : \"" + lookupName + "\",\"lookupCode\" : \"" + lookupCode + "\"},";
						}
						colCode = colCode.substring(0, colCode.length() - 1);
						colCode = colCode + "]";
					}
					if (!"".equals(colCode)) {
						JSONArray codeJson = JSONArray.fromObject(colCode);
						map.put("codeJson", codeJson);
					} else {
						map.put("codeJson", "[]");
					}
					map.put("flag", "success");
				} else if ("2".equals(colGeneMethod)) { // 序列
					map.put("flag", "success");
				} else if ("3".equals(colGeneMethod)) { // 顺带
					map.put("flag", "success");
				} else if ("4".equals(colGeneMethod)) { // 组合项
					/*
					 * // 查找表中的colName（lookupCode）和colLabel（lookupName） String colNameStr = commTableManagerService .getColNmaeByColType(tableId, cbbTabcolumns.getColType(),
					 * cbbTabcolumns.getColName()); mav.addObject("colNameStr", colNameStr);
					 */
					// 构造选择下拉列表
					String colNameStr = commTableManagerService.getColNmaeByColType(tableId, cbbTabcolumns.getColType(), cbbTabcolumns.getId(), ThreadContextHelper.getOrgId(), ThreadContextHelper.getDeptId(), sysId, nodeId);
					map.put("colNameStr", colNameStr);
				} else if ("5".equals(colGeneMethod)) { // 统计生成
					// 查找可组合字段构造下拉列表数据
					String colNameStr = commTableManagerService.getColNameByColTypeForTJSC(tableId, cbbTabcolumns.getColType(), cbbTabcolumns.getId(), ThreadContextHelper.getOrgId(), ThreadContextHelper.getDeptId(), sysId, nodeId);
					map.put("colNameStr", colNameStr);
				}
			} else if ("2".equals(dropdownType)) { // 只选
				if ("1".equals(colGeneMethod)) { // 默认值
					// 获取该字段通用代码集合
					List<Object[]> colCodeList = commTableManagerService.getLookupCodeByColumnId(id);
					// 构造json串
					String colCode = "";
					if (colCodeList.size() > 0) {
						colCode = colCode + "[";
						for (int j = 0; j < colCodeList.size(); j++) {
							String lookupName = String.valueOf(colCodeList.get(j)[0]);// 显示值
							String lookupCode = String.valueOf(colCodeList.get(j)[1]);// 真实值
							colCode = colCode + "{\"lookupName\" : \"" + lookupName + "\",\"lookupCode\" : \"" + lookupCode + "\"},";
						}
						colCode = colCode.substring(0, colCode.length() - 1);
						colCode = colCode + "]";
					}
					if (!"".equals(colCode)) {
						JSONArray codeJson = JSONArray.fromObject(colCode);
						map.put("codeJson", codeJson);
					} else {
						map.put("codeJson", "[]");
					}
					map.put("flag", "success");
				} else if ("2".equals(colGeneMethod)) { // 序列
					throw new Exception("配置非法");
				} else if ("3".equals(colGeneMethod)) { // 顺带
					map.put("flag", "success");
				} else if ("4".equals(colGeneMethod)) { // 组合项
					throw new Exception("配置非法");
				} else if ("5".equals(colGeneMethod)) { // 统计生成
					throw new Exception("配置非法");
				}
			} else if ("3".equals(dropdownType)) { // 选择
				if ("1".equals(colGeneMethod)) { // 默认值
					if ("user".equals(colRuleName)) {
						// 构造json串
						String colCode = "[{\"lookupName\" : \"当前用户\",\"lookupCode\" : \"currentUser\"}]";
						JSONArray codeJson = JSONArray.fromObject(colCode);
						map.put("codeJson", codeJson);
					}
					if ("dept".equals(colRuleName)) {
						// 构造json串
						String colCode = "[{\"lookupName\" : \"当前部门\",\"lookupCode\" : \"currentDept\"},";
						colCode = colCode + "{\"lookupName\" : \"当前上级部门\",\"lookupCode\" : \"parentDept\"}]";
						JSONArray codeJson = JSONArray.fromObject(colCode);
						map.put("codeJson", codeJson);
					}
					if ("custom".equals(colRuleName)) { // 自定义选择页
						// 将path传到页面
						String customPath = cbbTabcolumns.getCustomPath();
						map.put("customPath", customPath);
					}
					map.put("colRuleName", colRuleName);
				} else if ("3".equals(colGeneMethod)) { // 顺带
					map.put("flag", "success");
				} else if (!"0".equals(colGeneMethod)) {
					throw new Exception("配置非法");
				}
			} else { // 普通字段
				if ("1".equals(colGeneMethod)) { // 默认值
					/*
					 * String colLength = String.valueOf(cbbTabcolumns .getColLength()); mav.addObject("colType", colType); mav.addObject("colLength", colLength);
					 */
					// 根据字段类型进行拼写JSON
					if ("string".equals(colType) || "colb".equals(colType)) {
						// 构造json串
						String colCode = "[{\"lookupName\" : \"当前用户\",\"lookupCode\" : \"currentUser\"},";
						colCode = colCode + "{\"lookupName\" : \"当前部门ID\",\"lookupCode\" : \"currentDeptId\"},";
						colCode = colCode + "{\"lookupName\" : \"当前部门名称\",\"lookupCode\" : \"currentDeptName\"},";
						colCode = colCode + "{\"lookupName\" : \"当前组织代码\",\"lookupCode\" : \"currentOrg\"},";
						colCode = colCode + "{\"lookupName\" : \"当前全宗名称\",\"lookupCode\" : \"currentQzName\"},";
						colCode = colCode + "{\"lookupName\" : \"当前全宗代码\",\"lookupCode\" : \"currentQzCode\"},";
						colCode = colCode + "{\"lookupName\" : \"当前数据节点属性\",\"lookupCode\" : \"currentNodeRemark\"},";
						colCode = colCode + "{\"lookupName\" : \"当前上级部门名称\",\"lookupCode\" : \"parentDeptName\"},";
						colCode = colCode + "{\"lookupName\" : \"当前上级部门ID\",\"lookupCode\" : \"parentDeptId\"},";
						colCode = colCode + "{\"lookupName\" : \"当前上级部门代码\",\"lookupCode\" : \"parentDeptCode\"}]";
						JSONArray codeJson = JSONArray.fromObject(colCode);
						map.put("codeJson", codeJson);
					} else if ("date".equals(colType)) {
						// 构造json串
						String colCode = "[{\"lookupName\" : \"当前时间\",\"lookupCode\" : \"currentDate\"}]";
						JSONArray codeJson = JSONArray.fromObject(colCode);
						map.put("codeJson", codeJson);
					}
					map.put("flag", "success");
				} else if ("2".equals(colGeneMethod)) { // 序列
					if ("string".equals(colType)) {
						map.put("flag", "success");
					} else if ("integer".equals(colType)) {
						map.put("flag", "success");
					} else if ("float".equals(colType)) {
						map.put("flag", "success");
					} else if ("date".equals(colType)) {
						throw new Exception("配置非法");
					} else if ("colb".equals(colType)) {
						map.put("flag", "success");
					}
				} else if ("3".equals(colGeneMethod)) { // 顺带
					map.put("flag", "success");
				} else if ("4".equals(colGeneMethod)) { // 组合项
					if ("date".equals(colType)) {
						throw new Exception("配置非法");
					} else {
						// 查找表中的colName（lookupCode）和colLabel（lookupName）
						String colNameStr = commTableManagerService.getColNmaeByColType(tableId, cbbTabcolumns.getColType(), cbbTabcolumns.getId(), SessionHelper.getCurrentOrgId(request), SessionHelper.getCurrentDeptId(request), sysId, nodeId);
						if (!"".equals(colNameStr)) {
							map.put("colNameStr", colNameStr);
						} else {
							throw new Exception("无【" + cbbTabcolumns.getColType() + "】类型字段可以组合");
						}
					}
				} else if ("5".equals(colGeneMethod)) { // 统计生成
					// 查找可组合字段构造下拉列表数据
					String colNameStr = commTableManagerService.getColNameByColTypeForTJSC(tableId, cbbTabcolumns.getColType(), cbbTabcolumns.getId(), SessionHelper.getCurrentOrgId(request), SessionHelper.getCurrentDeptId(request), sysId, nodeId);
					map.put("colNameStr", colNameStr);
				}
			}
			map.put("dropdownType", dropdownType);
		} catch (Exception e) {
			map.put("flag", "failure");
			map.put("mes", e.getMessage());
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 保存生成方式配置信息
	 *
	 * @author 郭亮
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/saveConfig")
	public ModelAndView saveConfig(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView();
		String sysId = request.getParameter("sysId");

		sysId = "LANTOP";
		String nodeId = request.getParameter("nodeId");
		String nodeName = request.getParameter("nodeName");
		String tableName = request.getParameter("tableName");
		String id = request.getParameter("id");
		String colGeneMethod = request.getParameter("colGeneMethod");
		String colGeneMethodRule = request.getParameter("colGeneMethodRule");
		String json = request.getParameter("json");// 组合项配置信息
		// 统计生成配置信息
		String operation = request.getParameter("operation");// 统计生成运算方式
		String groupSelect1 = request.getParameter("groupSelect1");
		String groupSelect2 = request.getParameter("groupSelect2");
		String groupSelect3 = request.getParameter("groupSelect3");
		String groupInput1 = request.getParameter("groupInput1");
		String groupInput2 = request.getParameter("groupInput2");
		// 查询tableId
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orgId", SessionHelper.getCurrentOrgId(request));
		String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
		SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
		String orgCode = so.getOrgCode();
		String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
		// 根据tableId查找表是否为真实表
		String isTrueTable = commTableManagerService.findTableisTureTable(tableId);
		boolean flag = true;
		if ("N".equals(isTrueTable)) {
			flag = false;
		}
		// 根据id查找对象
		CbbTabColumns cbbTabcolumns = commTableManagerService.getCbbTabColumnsById(id);
		// 如果为组合项，解析配置json，设置生成方式规则值
		if ("4".equals(colGeneMethod)) {
			String configGroupValue = "";
			JSONArray ja = JSONArray.fromObject(json);
			for (int i = 0; i < ja.size(); i++) {
				JSONObject jj = JSONObject.fromObject(ja.get(i));
				String tgtColumnId = jj.getString("0");// 组合字段
				String tgtInput = jj.getString("1");// 组合固定值
				if (null != tgtColumnId && !"".equals(tgtColumnId) && !"null".equals(tgtColumnId)) {
					configGroupValue = configGroupValue + "+" + tgtColumnId;
				}
				if (null != tgtInput && !"".equals(tgtInput) && !"null".equals(tgtInput)) {
					configGroupValue = configGroupValue + "+'" + tgtInput + "'";
				}
			}
			if (!"".equals(configGroupValue)) {
				configGroupValue = configGroupValue.substring(1);
			}
			colGeneMethodRule = configGroupValue;
		}
		// 更新属性值
		cbbTabcolumns.setColGeneMethod(colGeneMethod);
		cbbTabcolumns.setColGeneMethodRule(colGeneMethodRule);
		// 调用方法更新对象
		CbbTabColumns[] cbbTabColumnsArray = new CbbTabColumns[1];
		cbbTabColumnsArray[0] = cbbTabcolumns;
		try {
			// 张余修改
			// 获取当前多语言类型
			Object lang = request.getSession().getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
			String languageCode = "zh_CN";
			if (lang != null) {
				languageCode = lang.toString();
			}
			params.put("languageCode", languageCode);
			params.put("orgCode", orgCode);
			commTableManagerService.updateCbbTabColumns(cbbTabColumnsArray, sysId, nodeId, nodeName, tableName, flag, params);
			if ("4".equals(colGeneMethod)) { // 保存组合项的配置信息
				commTableManagerService.saveConfigGroupNew(id, json, SessionHelper.getCurrentOrgId(request), SessionHelper.getCurrentDeptId(request), sysId);
			} else if ("5".equals(colGeneMethod)) { // 保存统计生成配置信息
				/*** 保存统计生成信息 ***/
				String[] configColumns = new String[3];
				String[] configInput = new String[2];
				String[] orders = new String[3];
				// 统计字段字段名数组
				configColumns[0] = groupSelect1.equals("") ? "" : groupSelect1;
				configColumns[1] = groupSelect2.equals("") ? "" : groupSelect2;
				configColumns[2] = groupSelect3.equals("") ? "" : groupSelect3;
				// 统计字段输入值数组
				configInput[0] = groupInput1.equals("") ? "" : groupInput1;
				configInput[1] = groupInput2.equals("") ? "" : groupInput2;
				// 统计字段顺序数组
				orders[0] = groupSelect1.equals("") ? "" : "1";
				orders[1] = groupSelect2.equals("") ? "" : "2";
				orders[2] = groupSelect3.equals("") ? "" : "3";
				commTableManagerService.saveConfigTJSC(id, configColumns, configInput, tableId, SessionHelper.getCurrentOrgId(request), SessionHelper.getCurrentDeptId(request), sysId, orders, operation);
			}
			mav.addObject("flag", "success");
		} catch (Exception e) {
			e.printStackTrace();
			mav.addObject("flag", "failure");
		}
		return mav;
	}

	/**
	 * 生成规则选择删除方法
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/deleteSelectRuleData")
	public ModelAndView deleteSelectRuleData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView("");
		String deleteData = request.getParameter("deleteData");
		try {
			// 删除
			if (!"".equals(deleteData) && !"[]".equals(deleteData)) {
				JSONArray ja = JSONArray.fromObject(deleteData);
				for (int i = 0; i < ja.size(); i++) {
					JSONObject jj = JSONObject.fromObject(ja.get(i));
					String id = jj.getString("ID");
					if (!"".equals(id) && !"null".equals(id) && null != id) {
						CbbTabFormSelect cbbTabFormSelect = commTableManagerService.getCbbTabFormSelectById(id);
						commTableManagerService.deleteCbbTabFormSelectById(cbbTabFormSelect);
					}
				}
			}
			mav.addObject("flag", OpResult.success);
		} catch (Exception e) {
			mav.addObject("flag", OpResult.failure);
			mav.addObject("mes", e.getMessage());
			e.printStackTrace();
		}
		mav.setView(null);
		return mav;
	}

	/**
	 * 生成方式规则保存方法
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/saveSelectRuleData")
	public ModelAndView saveSelectRuleData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView("");
		String insertData = request.getParameter("insertData");
		String sysId = request.getParameter("sysId");
		try {
			// 新增
			if (!"".equals(insertData) && !"[]".equals(insertData)) {
				JSONArray ja = JSONArray.fromObject(insertData);
				for (int i = 0; i < ja.size(); i++) {
					JSONObject jj = JSONObject.fromObject(ja.get(i));
					String selCode = jj.getString("SEL_CODE");
					String selName = jj.getString("SEL_NAME");
					String selUrl = jj.getString("SEL_URL");
					CbbTabFormSelect cbbTabFormSelect = new CbbTabFormSelect();
					cbbTabFormSelect.setSelCode(selCode);
					cbbTabFormSelect.setSelName(selName);
					cbbTabFormSelect.setSelUrl(selUrl);
					cbbTabFormSelect.setSysId(sysId);
					cbbTabFormSelect.setOrgId(SessionHelper.getCurrentOrgId(request));
					cbbTabFormSelect.setDeptId(SessionHelper.getCurrentDeptId(request));
					commTableManagerService.insertCbbTabFormSelect(cbbTabFormSelect);// 调用新增方法
				}
			}
			mav.addObject("flag", OpResult.success);
		} catch (Exception e) {
			mav.addObject("flag", OpResult.failure);
			e.printStackTrace();
		}
		mav.setView(null);
		return mav;
	}

	/**
	 * 参考模板复制字段信息加载库结构树
	 *
	 * @author 郭亮
	 * @param id
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/findStructureNodes")
	public ModelAndView findStructureNodes(String id, HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView();
		String copyNodeData = request.getParameter("copyNodeData");// 视图名称
		String sysId = request.getParameter("sysId");// 系统代码
		sysId = "LANTOP";
		List<TreeNode> nodes = new ArrayList<TreeNode>();
		try {
			// 默认为根节点
			if (StringUtils.isEmpty(id)) {
				id = "ROOT";
			}
			nodes = this.commTableManagerService.recurFindTreeNodesByParentIdInCommTemplet(id, copyNodeData, sysId, SessionHelper.getCurrentOrgId(request));
			mv.addObject("flag", OpResult.success);
		} catch (Exception e) {
			mv.addObject("flag", OpResult.failure);
			mv.addObject("msg", "后台处理异常，" + e.getMessage());
		}
		mv.addObject("data", nodes);
		return mv;
	}

	/**
	 * 唯一索引界面获取字段下拉框列表数据
	 *
	 * @author 朱锋
	 * @param id
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/getColLabelData")
	@ResponseBody
	public Map<String,Object> getColLabelData(String id, HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		// 获取参数
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String tableName = request.getParameter("tableName");
		// String nodeId = request.getParameter("nodeId");
		// String nodeName = request.getParameter("nodeName");
		// 查询tableId
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orgId", ThreadContextHelper.getOrgId());
		String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
		// 获取tableTitle
		// CbbTables cbbTables = commTableManagerService.getCbbTablesById(tableId);
		// String tableTitle = cbbTables.getTableTitle();
		// 根据表ID获取设置为可见的字段集合
		List<Object[]> list = commTableManagerService.getCbbTabColsByTableId(tableId);
		StringBuffer data = new StringBuffer();
		data.append("[");
		for (int i = 0; i < list.size(); i++) {
			Object[] obj = list.get(i);
			String colId = String.valueOf(obj[0]);// 列ID
			String colLabel = String.valueOf(obj[1]);// 列中文名
			data.append("{'id':");
			data.append("'" + colId + "',");
			data.append("'text':");
			data.append("'" + colLabel + "'");
			if (i == list.size() - 1) {
				data.append("}");
			} else {
				data.append("},");
			}
		}
		data.append("]");
		JSONArray ja = JSONArray.fromObject(data.toString());
		map.put("data", ja);
		return map;
	}

	/**
	 * 索引主页面数据删除方法
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/deleteCbbTabIndexData")
	@ResponseBody
	public Map<String,Object> deleteCbbTabIndexData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String deleteData = request.getParameter("deleteData");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String nodeId = request.getParameter("nodeId");
		String nodeName = request.getParameter("nodeName");
		String tableName = request.getParameter("tableName");
		String orgId = ThreadContextHelper.getOrgId();
		String deptId = ThreadContextHelper.getDeptId();
		try {
			// 删除
			commTableManagerService.deleteCbbTabIndexDataById(deleteData, sysId, nodeId, nodeName, tableName, orgId, deptId);
			map.put("flag", OpResult.success);
		} catch (Exception e) {
			map.put("flag", OpResult.failure);
			map.put("mes", "删除操作异常，请联系管理员！");
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 索引主页面数据保存方法
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/saveCbbTabIndexData")
	@ResponseBody
	public Map<String,Object> saveCbbTabIndexData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String insertData = request.getParameter("insertData");
		String updateData = request.getParameter("updateData");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String nodeId = request.getParameter("nodeId");
		String nodeName = request.getParameter("nodeName");
		String tableName = request.getParameter("tableName");
		try {
			// 查询tableId
			Map<String, Object> params = new HashMap<String, Object>();
			params.put("orgId", ThreadContextHelper.getOrgId());
			String tableId = commTableManagerService.getTableIdBysysIdAndTableName(sysId, tableName, params);
			// 新增
			if (!"".equals(insertData) && !"[]".equals(insertData)) {
				if (!"".equals(tableId)) {
					// 存在，那么新增列信息及更新实体表
					commTableManagerService.insertCbbTabIndex(insertData, sysId, nodeId, nodeName, tableName, ThreadContextHelper.getOrgId(), ThreadContextHelper.getDeptId(), SessionHelper.getLoginSysUserId(request), RequestUtil.getClientIp(request));
					map.put("flag", OpResult.success);
				}
			}
			// 更新
			if (!"".equals(updateData) && !"[]".equals(updateData)) {
				if (!"".equals(tableId)) {
					// 存在，那么新增列信息及更新实体表
					commTableManagerService.updateCbbTabIndex(updateData, sysId, nodeId, nodeName, tableName, ThreadContextHelper.getOrgId(), ThreadContextHelper.getDeptId(), SessionHelper.getLoginSysUserId(request), RequestUtil.getClientIp(request));
					map.put("flag", OpResult.success);
				}
			}
		} catch (Exception e) {
			map.put("flag", OpResult.failure);
			map.put("mes", "不能给同一字段中文名添加同一类型的索引，请查证！");
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 唯一索引界面获取字段下拉框列表数据
	 *
	 * @author 朱锋
	 * @param id
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/getColIndexNameData")
	@ResponseBody
	public Map<String,Object> getColIndexNameData(String id, HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		// 获取参数
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		// String nodeId = request.getParameter("nodeId");
		// String nodeName = request.getParameter("nodeName");
		// String tableName = request.getParameter("tableName");
		String insertData = request.getParameter("insertData");
		// 查询tableId
		// String tableId = commTableManagerService.getTableIdBysysIdAndTableName(
		// sysId, tableName);
		String colId = request.getParameter("colId");
		// 根据列ID，查询该列的数据
		CbbTabColumns cbbTabColumns = commTableManagerService.getCbbTabColumnsById(colId);
		String colName = cbbTabColumns.getColName();// 列名
		// 构造索引名
		String indexName = "IDX_" + sysId + "_" + colName;
		// 判断该索引名是否重复
		boolean flag = commTableManagerService.checkIndexNameIsUnique(indexName, insertData);
		int i = 0;
		while (!flag) {
			i++;
			String num = "";
			if (i < 10) {
				num = "0" + String.valueOf(i);
			} else {
				num = String.valueOf(i);
			}
			indexName = "IDX_" + sysId + "_" + colName + num;
			flag = commTableManagerService.checkIndexNameIsUnique(indexName, insertData);
		}

		map.put("colId", colId);
		map.put("colName", colName);
		map.put("indexName", indexName);
		return map;
	}

	/**
	 * 语言选择页面
	 * @param type
	 * @param pid
	 * @param language
	 * @param appid
	 * @param timestamp
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/chooseLanguage/{pid}/{type}")
	public ModelAndView toChooseLanguage(@PathVariable
	String pid, @PathVariable
	String type, HttpServletRequest request) {
		ModelAndView mav = new ModelAndView();
		String url = "";
		if (type.equals("1")) {
			url = "platform/cbbtabcolumnstl/CbbTabColumnsTlController/operation/getAllLanguageById/" + pid;
		} else {
			url = "platform/cbbtabcolcodetl/CbbTabColCodeTlController/operation/getAllLookupTypeLanguageById/" + pid;

		}
		request.setAttribute("url", url);
		request.setAttribute("name", "lookupTypeName");// lookupName
		request.setAttribute("display", "列显示名称");
		request.setAttribute("flag", true);
		request.setAttribute("type", type);
		mav.setViewName("avicit/cbb/techclass/tabledefine/commtablemanager/chooseLanguage");
		return mav;
	}

	/**
	 * 字段基本信息更新方法(不操作数据库实体表)
	 *
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/syncCbbTabColumnsData")
	@ResponseBody
	public Map<String,Object> syncCbbTabColumnsData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new Map<String,Object>;
		String json = request.getParameter("param");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String nodeId = request.getParameter("nodeId");
		String nodeName = request.getParameter("nodeName");
		String tableName = request.getParameter("tableName");
		String deptId = ThreadContextHelper.getDeptId();
		String orgId = ThreadContextHelper.getOrgId();
		CbbTabColumns[] ccArray = JsonUtils.newInstance().Json2BeanArray(json, CbbTabColumns.class);// 实体类列对象数组
		// 如果是【代码维护】页面，那么给【生成方式】字段复制
		try {
			commTableManagerService.syntabNodeRecordData(ccArray, sysId, nodeId, nodeName, tableName, orgId, deptId);
			map.put("flag", OpResult.success);
		} catch (Exception e) {
			map.put("flag", OpResult.failure);
			e.printStackTrace();
		}
		return map;
	}
}
